Skip current 5 Bar and loop back for condition ?

 

Hi,


Example, I want to skip checking the Current 5 Bar, and loop back about 50 Bar to look for Condition of an indicator. If red, Sell only, If Green, Buy only.


This is my code but it's not working propertly...The reason i want to skip current 5 bar because the indicator Signaler repaint mostly appear at current bar, so i want to skip 5 bar and get the last signal.


bool Buyonly=false;
bool Sellonly=false;

int limit=50;
for(int i=5;i<=limit;i++)
{
double SignalGreen = iCustom(NULL,0,"Signaler",0,0,24,0,i);
double SignalRed = iCustom(NULL,0,"Signaler",0,0,24,1,i);

if (SignalGreen >0&&SignalGreen !=EMPTY_VALUE){Buyonly=true;break;}
if(SignalRed >0&&SignalRed !=EMPTY_VALUE){Sellonly=true;break;}
}

double bbBuy = iCustom(NULL,0,"ffsbb",8,0,1);
double bbSell = iCustom(NULL,0,"ffsbb",8,1,1);
if(Sellonly==true){if ((bbSell>0&&bbSell!=EMPTY_VALUE))Send Sell order}

if(Buyonly==true){if((bbBuy>0&&bbBuy!=EMPTY_VALUE))Send Buy order}

Please help me check the code..


Problem i have:

- When Buyonly is true, and bbBuy appears 1st time, Buy order send ok, but then bbBuy appear again, there is no trade ...

- Some time trade was made, example SELL even the Buyonly is true.

 

First off, I believe EMPTY_VALUE is a huge negative.. so if you're making sure that the signal is > 0, you won't have to check for EMPTY_VALUE. Vice-versa works as well if the value is assured to always be > 0.

Second, if you want to ignore the first 5 bars, you are already doing that by starting your for-loop at 5.

Third, the only way I see that your synchronization might become offbeat is if you don't actually have the sellonly and buyonly variables just above the for-loop in your real code. You need to make sure they are set to false before the loop and nothing is done to them before the check after exiting the loop. Based on your above code, there is no way that both of them could be true since you're breaking out before both can be checked if one is set to true.

Jon

Reason: