Showing posts with label algorithms. Show all posts
Showing posts with label algorithms. Show all posts

1/24/2019

random walk AOS

currently i have been programming quite a lot. this is one of the AOS that i built just for fun (and testing purpose).

it generates random entries with complete disregard to market data. the core is build on mercenne twister algorithm implemented in C++



i am pretty sure this will show up that COMPLETE RANDOMNESS generates quite similar (or even better) results compared to guys that "follow a plan"

8/23/2018

ACSIL code for getting point of control

this is full code for getting POC (maximum volume) of a bar from a given timeframe. might be good to test the reaction of price to the previous day for instance..


#include "sierrachart.h"
#include <vector>

SCSFExport scsf_POC(SCStudyInterfaceRef sc)
{
if (sc.SetDefaults)
{
sc.GraphName = "Identifying POC Values";
sc.GraphRegion = 0;
sc.Subgraph[0].Name = "POC Value";
sc.Subgraph[1].Name = "POC Price";

sc.MaintainVolumeAtPriceData = 1;

sc.AutoLoop = 1;
sc.FreeDLL = 1;

return;
}

int poc_value = 0; 
float poc_price = 0;
std::vector<int> v_poc_values = {};
std::vector<float> v_poc_prices = {};
const s_VolumeAtPriceV2 *p_volume_at_price = NULL;

int number_of_levels = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(sc.Index);
for (int i = 0; i < number_of_levels; i++)
{
if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, i, &p_volume_at_price))
break;

int last_volume_value = p_volume_at_price->Volume;
if (last_volume_value > poc_value)
{
poc_value = last_volume_value;
poc_price = p_volume_at_price->PriceInTicks * sc.TickSize;
v_poc_values.push_back(poc_value);
v_poc_prices.push_back(poc_price);
}
}

sc.Subgraph[0][sc.Index] = (float)poc_value;
sc.Subgraph[1][sc.Index] = (float)poc_price;

//log 
SCString log_prices;
SCString log_values;

if (v_poc_prices.size() != v_poc_values.size())
return;

for (int i = 0; i < v_poc_prices.size(); i++)
{
log_prices.Format("%f", v_poc_prices.at(i));
log_values.Format("%d", v_poc_values.at(i));
}

sc.AddMessageToTradeServiceLog(log_prices, 0); 
sc.AddMessageToTradeServiceLog(log_values, 1);
}

8/11/2018

ACSIL function for getting a market depth level value

simple, yet pretty useful function for getting values from particular levels at the depth of market

ACSIL Sierra Chart coding

this can serve as a building block for creating a study for timing entry based on the quoting limit side. something i plan to do..

ACSIL Sierra Chart coding


the good thing about this study is that you don't need to use historical market depth data on the chart, which makes it faster.

the line under the chart shows the (historical) value of bid and ask at the first level for each timestamp (here set to one second).

6/28/2018

numbers that matters

there is a holy grail hidden in these numbers

number of trades bid vs number of trades ask vs bid volume vs ask volume etc..

sierra chart acsil backtesting

this is what i am currently algo testing on sp500, dow, nasdaq, rty, crudeoil, heating oil, gold, silver, copper, 6a, 6b, 6c, and all other bunch of future markets

simple, easy, clean and fast

6/03/2018

super-bad backtest results from a super simple acsil code

i have been doing some acsil coding sierra chart lately and built up a couple of new setups.

sometimes it is quite time-consuming and difficult to build a good strategy that returns nice results.

of course, backtest are not the only thing to weight and worry about, but it is definitely the first thing u see.

the worst backtests are not the one that had poor results but the ones where the profit factor is somewhere around 1,00. it means that the profits and losses are equal.

some might think that the worst backtests are simply the ones with the worsts result, but no, that is not necessarily true. at least not for me..

because when i find a strategy that is really poor and loses 9 times out of 10 entries, i can simply change the direction for each entry and... voila, i got a pretty good scoring one.

today i run a backtest that returned really horrible results. i mean, i have never run a test that would be as bad as this one.

it has 0.23 profit factor which means that from each 5 entries, 4 of them go to sl..

i tested only 40 days, but the number of trades is 505 which is quite high.. so yeah, it might say something..

sierra chart acsil coding
next step?

reverse the position and run it on a longer frame..

maybe, this piece of crap will become one of the most profitable strategies in the entire freaking universe :-)

who knows..

5/12/2018

sierra chart acsil: couple of tips for adressing data from other charts

when it comes to acsil programming, sometimes you can get stuck in one place for a long time just because a simple tiny detail that you cannot solve out.

for me it was problems connected with setting up the size of arrays in overlaid charts. in sierra chart´s acsil libraries there are couple of functions for addressing the values of a different chart, but now matter which way i tried, it never worked out well.

i was able to transfer the data from other charts into my primary chart, but the values at a particular index were incorrect.

the reason was that the number of indexes in the arrays from other charts was not the same as the number of indexes in the primary one.

it sounds simple, and sierra chart support describes it in their documentation, but because i am a complete computer idiot, i was unable to get it done.

now i have finally fixed it so here i will give a couple of tips on how to do it.

first of all, a brief introduction.

why do we need to get the values of another chart, anyway?

simple example.

lets say u have found a trend pattern, but you want to open a trade only when tick nyse is above zero. for this, you need to get THE CORRECT value of tick nyse at the time (meaning at the current index) of the planned entry.

if tick nyse at the current index will be below zero, you will filter out the signal and no position will be opened, if it will be above, you will open. easy enough.

the problem is that the tick nyse starts at 8:30 and ends at 15:00
tick nyse - sierra chart acsil programming

us indexes (YM, NQ, ES..) starts at 8:30 and ends at 15:15
sierra chart intraday automated trading
thus it is obvious the number of indexes (the number of candlesticks) is different. and that is a big problem. if you wanna transfer the arrays (for example highs and lows) of tick nyse into the es chart and get the values for a particular candlestick at es, the values will be incorrect.

how to solve it?

easily

the first thing you should do in such a case is to re-set up the trading hours. normally i have trading hours in my charts like this because US indexes end at 15:15

acsil sierra chart automated trading

you have to set the trading hours according to the chart that has less number of candlesticks (in this case it is tick nyse). so it should finish at 15:00

sierra chart acsil programming

after that, it is important to set the linking with all the other charts (if u have any) so that you are sure the number of indexes will be the same for each array of each chart.

this is super important if you work with more charts that just two (just like me) and want to address the values of their arrays for computing correlations (just like me)

sierra chart acsil programming

so this is the basic setting for working with an array of any other chart in the same chartbook. this should be used as defaults, otherwise, the values will never be correct.

after that, you have to choose which way to address the values of other charts.

i use acsil´s graphdata object which is implemented in sierra chart and works pretty fine, but there are a couple of other ways to do it (for example using overlay study and addressing the values of the overlaid chart as a subgraph).

anyhow, the code for getting high, low, close arrays from three different charts can look like this:

sierra chart acsil programming - visual studio

this is i would say the kernel for whatever you need when it comes to getting correct values from a particular chart. the code is pretty easy and simple, and the values that you get can be used in the same way as the values of the primary chart (eg. sc.low[sc.index], sc.high[sc.index] etc..)

pretty straightforward..

5/11/2018

another sierra chart acsil study

i have been currently working on another acsil study which will measure intermarket divergence and filter out some trades in case the markets are too dis-correlated.

this is going to be quite a useful study which i plan to implement into all the automatic trading system. i use correlations a lot in my discretional trading and finaly i have found a way how to solve it programmatically.

4/26/2018

study of velocity

this is a new, quite simple but very useful study that i wrote a couple of days ago to measure the price velocity or "volatility" if you want.

probably most of you know ATR indicator which is commonly used by all who want to track the volatility or its changes. but the problem with ATR is, that it doesn´t really show much about how the price behaved.

it only calculates the difference of highs and lows of a bar and then divides this number by a preset variable to return an average. if you have a bar which has 10 ticks in size (high-low) than the true range is 10. very simple.

but it doesn´t tell much about HOW the price behaved within the period of the ten ticks. maybe it moved 9 ticks up, then nine 9 down, then again 9 ticked up, down, up, down, up, down.. you got the idea.. within just one bar.

so at the end of the day, the price could make 100 ticks long movement which is hidden within a single bar..

this study - which i called velocity - on the other hand, calculates how many times the price changed within a period time. so u get the precise number of the volatility. or we might say "nervosity" of price.

i did not have time to test it much but it looks promising mostly as an input to automatic trade-management for algorithmic trading..

here is a simple example (subgraph 2) - you can see that even though the candlesticks are of the same size all the time, the velocity studies gradually goes down

acsil sierra chart programming

1/13/2018

orderflow aos based on acsil

this is the result of a 100% automatic strategy based on order flow that i have built in acsil - a sierra chart programming environment based on c++.

i am NOT a programmer and i have really hard time to write a piece of code. yet, i have a strong desire to learn and move forward.

it is trading live with 2 contracts only. after 2 days it made a profit almost 2 thousand usd. that is not a bad beginning i would say..
acsil programming aos based on orderflow - sierra chart trade log

4/28/2017

big subject activity on daily low - scalping algo breakout

this is what i have noticed today on daily low at e-mini nasdaq 100 futures somewhere around 13:10 chicago time
the interpretation of this visualization is this: near daily low a big rough market and a big sell market order of the same quantity appeared. it was immediately identified by an algorithm which started selling using sell markets in a "clever" manner.

at the same time, sell markets were supported with huge sell limit (on the depth of market as the white line). when no one wanted to buy this big amount and fill the huge sell limit, the subject starts selling in a harsh manner - using big sell market orders. the price drops a little bit down and the subject closes the position in a "clever" way using smart activity. taking profit.

the price made a small pullback up and the algorithm started selling again, using a high amount of sell market orders in a matter of (mili)seconds. at the same time, big sell limit appeared at the depth of market, was filled this time with a big buy market order and the price slides lower. the selling subject closed the position in a smart way, taking profit again.

again, it started opening bigger sell markets now to break the daily low. its big sell limits were strong enough to eat all the offered liquidity in the dept of market. 

at the break of the daily low a 100-contracts big buy market order tried to protect the zone, but was neutralized with a 100-contracts sell limit. moreover, the 100 sell limit was supported with an even bigger sell limit (the size cca 230) accompanied with sell market in the size 120! it hit the daily low, closing the position in a clever way, taking its profit (yes again!) and reversing the position for long.

this is how a very powerful and very clever scalping algorithms operate..

this is where it happened in the chart (daily low - sensitive area)

this is how the footprint charts of the area looks like