// basic priceatbuy code by Tomasz Janeczko, multiple modifications by trash
delay = 1;
SetTradeDelays( delay, delay, delay, delay );// used in analysis
SetPositionSize( 10, spsPercentOfEquity );
if ( delay > 0 )
{
array = Open;
}
else
{
array = Close;
}
Buy = Sell = 0;
Short = Cover = 0;
BuyPrice = SellPrice = array;
_MA = MA( C, 20 );
BuyConditions = Cross( C, _MA );
priceatbuy = Null;
priceatsell = Null;
patba = Null; // PriceAtBuy Array (for plotting only)
patse = Null;
for ( i = delay; i < BarCount; i++ )
{
SellSignal = array[ i ] > priceatbuy;
[COLOR="red"]Here is a condition, right? Sellsignal is true if array[i]
is higher than priceatbuy. But how can this conditional work
if priceatbuy is null, as setted above? It means it
will always be null. [/COLOR]
if ( SellSignal AND NOT IsNull( priceatbuy ) )
[COLOR="red"]Again, how can SellSignal be anything
other than null? or is sellsignal some kind of
built in function? [/COLOR]
{
Sell[ i - delay ] = 1;
priceatbuy = Null;
priceatsell = SellPrice[i];
}
BuySignal = BuyConditions[ i - delay ];
if ( IsNull( priceatbuy ) AND BuySignal )
{
Buy[ i - delay ] = 1;
priceatbuy = BuyPrice[ i ];
priceatsell = Null;
}
// to plot price at buy and sell you need an ARRAY, not scalar
patba[ i ] = priceatbuy;
patse[ i ] = priceatsell;
}
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
Plot( C, "Close", ParamColor( "Color Price", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle(), 0, 1, 0, 0);
Plot( patba, "priceatbuy", colorGreen, styleLine, Null, Null, 0, 1 );
Plot( patse, "priceatsell", colorRed, styleLine, Null, Null, 0, 1 );
Plot( _MA, "MA", ParamColor( "Color MA", colorCycle ), styleLine );
PlotShapes( Buy*shapeUpArrow, colorGreen, 0, H, -15 );
PlotShapes( Buy*shapeHollowUpArrow, colorWhite, 0, H, -15 );
PlotShapes( Ref( Buy, -delay )*shapeHollowSmallCircle, colorGreen, 0, BuyPrice, 0 );
PlotShapes( Sell*shapeDownArrow, colorRed, 0, H, -15 );
PlotShapes( Sell*shapeHollowDownArrow, colorWhite, 0, H, -15 );
PlotShapes( Ref( Sell, -delay )*shapeHollowSmallCircle, colorRed, 0, SellPrice, 0 );