Could someone help me to debug the code?

#1
Here is the code:

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();
	}
}
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
 

mastermind007

Well-Known Member
#2
Here is the code:

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();
	}
}
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
you are getting no output because you've not asked Amibroker to output anything. Hint: Plot, PlotShapes

Second point, Amibroker does not handle Arrays in same way that Ninja or Metatrader or C++ do.

You seem to be a programmer with some good experience so just read up the Amibroker help and you'll be set
 

Similar threads