Here is the code:
The code above is to mimic the Magic T-theory.
However, after scanning the share price, there is no output. I don't know what's happening. Could anyone help me to debug the code? Thanks
Code:
SetPositionSize(400, spsShares);
FastMovingAvg = MA(C,10);
SlowMavingAvg = MA(C,20);
RiseSignal = Cross(FastMovingAvg, SlowMavingAvg);
DropSignal = Cross(SlowMavingAvg, FastMovingAvg);
DateTimeArray = DateTime();
PositionHold = 0;
DropStartTime = 0;
RiseStartTime = 0;
DropStartPrice = 0;
function resetVariables()
{
PositionHold = 0;
DropStartTime = 0;
RiseStartTime = 0;
DropStartPrice = 0;
}
Buy = 0;
Sell = 0;
for (i = 0; i<BarCount; i++)
{
if (DropSignal[i] && PositionHold = 0)
{
DropStartTime = DateTimeArray[i];
DropStartPrice = C[i];
}
else if (DropStartPrice > 0 && RiseSignal[i])
{
RiseStartTime = DateTimeArray[i];
TargetBuyPrice = (DropStartPrice - C[i])/3+C[i];
}
else if (DateTimeDiff(RiseStartTime, DropStartTime) > 0 && C[i] >= TargetBuyPrice && PositionHold == 0)
{
Buy[i] = 1;
PositionHold++;
}
else if (PositionHold > 0 && DateTimeDiff(DateTimeArray[i], RiseStartTime) >= DateTimeDiff(RiseStartTime, DropStartTime))
{
Sell[i] = 1;
resetVariables();
}
}
However, after scanning the share price, there is no output. I don't know what's happening. Could anyone help me to debug the code? Thanks