Home › Forums › Trading System Mentor Course Community › AmiBroker Coding and AFL › magical disappearing / reappearing signals
- This topic is empty.
-
AuthorPosts
-
January 23, 2016 at 3:26 am #101397AnonymousInactive
hi all,
i have noticed when plotting loops that have trailing stops and buy/sell signals, the signals and stop lines will disappear and reappear depending on where you are scrolling through a chart.just wondering if this a common problem or specific to my amibroker setup?
the code below shows and example of this while scrolling back and forth betwen years 2003 and 2004 over CBA
buySetup = Cross(MACD(),0);
longEntry = Ref(buySetup,-1);
trailStop = High * (1 – 0.2);Buy = 0;
Sell = 0;
longStop = Null;
priceAtBuy = 0;
longBIT = 0;
bELevel = Null;for (j=1; j < BarCount; j++)
{
if(priceAtBuy==0 AND longEntry[j])
{
Buy[j] = True;
BuyPrice = Open[j];
priceAtBuy = BuyPrice[j];
longStop[j] = Max(trailStop[j-1],trailStop[j]);
longStop[j-1] = trailStop[j-1];
bELevel[j] = priceAtBuy[j];
longBIT[j] = 1;if(longBIT[j] > 1 AND Close[j-1] <= longStop[j-1])
{
Sell[j] = True;
SellPrice[j] = Open[j];
priceAtBuy = 0;
}
}else
if(priceAtBuy > 0)
{
longBIT[j] = longBIT[j-1] + 1;if(longBIT[j] > 1)
{
longStop[j] = Max(longStop[j-1],trailStop[j]);
beLevel = bELevel[j-1];
}if(longBIT[j] > 1 AND Close[j] > (bELevel[j-1]*1.1))
{
longStop[j] = Max(longStop[j],bELevel[j-1]);
}if(longBIT[j] > 1 AND Close[j-1] <= longStop[j-1])
{
Sell[j] = True;
SellPrice = Open[j];
priceAtBuy = 0;
}
}
}//
// plot setup
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot(Close,””,colorDefault,styleBar);
Plot(longStop,””,colorBlue,styleLine);PlotShapes(shapeUpArrow*Buy,colorGreen,0,L,-80);
PlotShapes(shapeDownArrow*Sell,colorRed,0,H,-80);PlotShapes(shapehollowUpArrow*buySetup,colorGreen,0,L,-100);
January 23, 2016 at 7:02 pm #102439SaidBitarMemberTry this
beLevel[j] = bELevel[j-1];
// i just noticed that you missed [j] for the left part of the equation
January 23, 2016 at 7:08 pm #102509SaidBitarMemberNow i saw what you are talking about
use this
Code:SetBarsRequired(sbrAll,0);buySetup = Cross(MACD(),0);
longEntry = Ref(buySetup,-1);
trailStop = High * (1 – 0.2);Buy = 0;
Sell = 0;
longStop = Null;
priceAtBuy = 0;
longBIT = 0;
bELevel = Null;for (j=1; j < BarCount; j++) { if(priceAtBuy==0 AND longEntry[j]) { Buy[j] = True; BuyPrice = Open[j]; priceAtBuy = BuyPrice[j]; longStop[j] = Max(trailStop[j-1],trailStop[j]); longStop[j-1] = trailStop[j-1]; bELevel[j] = priceAtBuy[j]; longBIT[j] = 1; if(longBIT[j] > 1 AND Close[j-1] <= longStop[j-1]) { Sell[j] = True; SellPrice[j] = Open[j]; priceAtBuy = 0; } } else if(priceAtBuy > 0)
{
longBIT[j] = longBIT[j-1] + 1;if(longBIT[j] > 1)
{
longStop[j] = Max(longStop[j-1],trailStop[j]);
beLevel[j] = bELevel[j-1];
}if(longBIT[j] > 1 AND Close[j] > (bELevel[j-1]*1.1))
{
longStop[j] = Max(longStop[j],bELevel[j-1]);
}if(longBIT[j] > 1 AND Close[j-1] <= longStop[j-1]) { Sell[j] = True; SellPrice = Open[j]; priceAtBuy = 0; } } } // // plot setup SetChartOptions(0,chartShowArrows|chartShowDates); Plot(Close,"",colorDefault,styleBar); Plot(longStop,"",colorBlue,styleLine); PlotShapes(shapeUpArrow*Buy,colorGreen,0,L,-80); PlotShapes(shapeDownArrow*Sell,colorRed,0,H,-80); PlotShapes(shapehollowUpArrow*buySetup,colorGreen,0,L,-100);
January 24, 2016 at 3:45 am #102510Stephen JamesMemberTry this at the very beginning of the code:-
SetBarsRequired(sbrAll,0);
It stabilizes plots. It’s is mentioned in the course somewhere, but you may not be up to that yet. Also, check the user guide for a full description.
Monte Carlo code also disrupts plots, but that comes later in the course.
-
AuthorPosts
- You must be logged in to reply to this topic.