Trying to implement an RSI-type strategy, which sets individual elements of alert signals within a loop, instead of exploiting the arrays using Cross, etc. I also need a C++ Turnup() function and a Cross function, since I can't use the entire array with an e.g. AB Cross function. Crossovers are quite tricky to implement, so are there any function implementations of Turnup or Cross in raw source code?
Last, for some reason the code below only trigger a Short, and then erroneously sends a Cover on the next bar. I tried to trap it out, but could not identify via the binary values (0,1) of buyStop and sellStop what was occurring. Also, I believe the open position vectors which I am setting to 0 or 1 for the entire array during alerts will work when simply testing for openposition[i]==0 or 1.
Altogether, I need to ensure the logical statements are working correctly, then attack the issue involving knowing whether a position is open or not.
I do have static variables already programmed for intraday, but right now I just need to this working ion for EOD.
if ( RSISignal[i] > RSISignal[i-1] AND RSISignal[i] < LowerBand[i] AND i>30) //this needs to be a TurnUp function
{
buyStop[i] = 1;
}
if ( ( (RSISignal[i-2]>UpperBand[i-2] AND RSISignal[i] < UpperBand[i] ) OR (RSISignal[i-2]>NeutralBand[i-2] AND RSISignal[i] < NeutralBand[i] ) ) AND emashort[i] < emalong[i] AND i>30) //This needs to a Cross function, triggereing when RSISignal goes below upper or neutral.
{
shortStop[i] = 1;
}
if( openposition[i]==1 )
{
//if ( TimeNow() > 145500 )
// Sell[i]=1; // Needs to be ExitAtMarket( i+1, p, "Time");
if( longposition[i]==1 )
{
if ( High[i] < entryprice[i] + pLongDelta )
{
Sell[i]=1; // Needs to be SellAtMarket( i+1, p, "Delta");
openposition=0;
longposition=0;
}
if ( shortStop[i]==1 )
{
Sell[i]=1; // Needs to be SellAtLimit( i+1, p, Close[i], "Limit");
openposition=0;
longposition=0;
}
}
else
{
if ( Low[i]> entryprice[i] + pShortDelta )
{
Cover[i]=1; // Needs to be CoverAtMarket( i+1, p, "Delta" );
openposition=0;
shortposition=0;
}
if ( buyStop[i]==1 )
{
Cover[i]=1; // Needs to be CoverAtMarket( i+1, p, "Cover" );
openposition=0;
shortposition=0;
}
}
}
else
{
if ( buyStop[i]==1 )
{
Buy[i]=1; // Needs to be BuyAtStop( i+1, Close[i], "Stop Buy" );
entryprice = LastValue(C);
openposition=1;
longposition=1;
}
if ( shortStop[i]==1 AND openposition[i]==0 )
Short[i]=1; // Needs to be ShortAtMarket( i+1, "Short" );
entryprice = LastValue(C);
openposition=1;
shortposition=1;
}
}