pl. fix exploration code

bharatk8

Active Member
#1
Hi

This system is simple.

If white bar closes near high with good volume and does not form DOJI,buy is TRIGGERED
on next bar open.

But exploration results records BUY AT BAR WHICH TRIGGERS THE BUY TRADE.

See image

Pl. correct AFL

regards

bharat

_SECTION_BEGIN("BackTest_ready For");
// backtest by ******** backtest 3-8-2011
/////////////////////////////// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
SetBarsRequired(10000,10); /* bars */
SetTradeDelays( 0, 0, 0, 0 ); /* delay entry/exit by zero bar */



////////////////////// /////////////////////
// HERE YOU WRITE YOUR CODE //BT TEMPLATE IS COPY PASTED BELOW MY AFL
mple=(C>O) AND (C==H) AND (V>Ref(V,-1)) AND NOT (O==C);
kokkino=(C<O) AND (C==L) AND (V>Ref(V,-1)) AND NOT (O==C); // delete the red lines it is onather system
Color=IIf(Mple,colorBlue,colorYellow );
Plot(C,"",Color,ParamStyle("Style Of Bars",styleBar,maskAll));
//here you must write what is SEXE ? OR NB1; ?
//what i mean you must write your main code


// below write all conditions for buy,sell to fiil them up if you wish ...
//--------------------- condition Long
Buy=mple;


//--------------------- condition SELL
CondSL1=(H<Ref(H,-1)) OR (L<Ref(L,-1));



//--------------------- condition short

Short=kokkino;

//--------------------- condition Cover
CondC1=(L>Ref(L,-1)) OR (H>Ref(L,-1));



//----------yuo must enter below every of the above contistions that you like -----------
// for EXAMPLE BUYOK= CondL1=SEXE OR CondL5=NB8 AND CondL9=NUp1 AND NOT CondL13=bex;
// Buy = Ref(Buy,-1); BuyPrice = Open; //DECLARE THE"Open" OF THE NEXT BAR

Buyok =mple;

Sellok =CondSL1;

Shortok =kokkino;

Coverok =CondC1;
Buy = Ref(mple,-1); BuyPrice = Open; // "Open"
Short=Ref(kokkino,-1); ShortPrice=Open;

// -------- DO NOT TOUCH BELOW HERE IF YOU NOT KN/OW/ WHAT ARE YOU DOING ----------------------
//--------------------- trading hours 91600 to 153000
TradeTime=ParamToggle(" backTest with Time?", "No|Yes",0 ) ;
StartTime = ParamTime( "Start Time", "9:16" );
EndTime = ParamTime( "End Time", "15:30" );
EA = TimeNum() >= starttime AND TimeNum() <= endtime;

if (TradeTime) {
//--------------------- Buy, Sell, Short, Cover, Here is with time
Buy=buyOK AND EA; BuyPrice = Open;
Sell=SellOK OR EndTime ; SellPrice = Open;
Short= ShortOK AND EA; ShortPrice = Open;
Cover=CoverOK OR EndTime ; CoverPrice = Open;
TitleTradeTime= "\nBacktest TradeTime - With Time";
}
else {
//--------------------- Buy, Sell, Short, Cover, Here is without time
Buy=buyOK ; BuyPrice = Open;
Sell=SellOK ; SellPrice = Open;
Short= ShortOK ; ShortPrice = Open;
Cover=CoverOK ; CoverPrice = Open;
TitleTradeTime= "\nBacktest TradeTime - WithOut Time";
}

Buy= ExRem(Buy,Sell); Sell= ExRem(Sell,Buy);
Short= ExRem(Short,Cover); Cover=ExRem(Cover,Short);

// if(Status("Action")==actionScan OR Status("Action")==actionExplore)
// {
//--------------------- EXPLORATION
lastpriceBuy=ValueWhen(Buy,Open,1);
lastpriceSELL=ValueWhen(Sell,Open,1);
lastpriceShort=ValueWhen(Short,Open,1);
lastpriceCover=ValueWhen(Cover,Open,1);
BuyProfit= lastpriceSELL- lastpriceBuy; "BuyProfit= "+WriteVal(BuyProfit,1.4); // return a single trade BUY-Sell
ShortProfit =lastpriceShort-lastpriceCover; "ShortProfit= "+WriteVal(ShortProfit,1.4);

//// Gainers/Lossers
monodesLong= Cum(BuyProfit) ;
monadesShort=Cum(ShortProfit );
total= monodesLong+monadesShort;
Width60=60;
Filter = Buy OR Short; /* all symbols and quotes accepted */
colorBuyProfit = IIf(BuyProfit>0,colorBrightGreen,colorRed);
ColorShortProfit = IIf(ShortProfit >0,colorBrightGreen,colorRed);

SetOption("NoDefaultColumns", True);
AddTextColumn(Name(), "Symbol", 77, 1, colorDefault, 70);
AddColumn(DateTime(), "Date", formatDateTime, 1, colorDefault, 120);

AddColumn(IIf(Buy, Asc("B",0), Asc("S")), "PosL", formatChar);
AddColumn( Buy, "Buy", 1 );
AddColumn(IIf( Buy, lastpriceBuy, Null ) ,"BUY",1.4,colorDefault,colorDefault,60);
AddColumn(IIf(Sell,lastpriceSELL,Null),"SELL",1.4,colorDefault,colorDefault,60);
AddColumn(IIf(Sell,lastpriceSELL- Ref(lastpriceBuy,-1),Null),"LongPip",1.4,colorDefault,colorBuyProfit ,60);

AddColumn(IIf(Short, Asc("S",0), Asc("C")), "PosS", formatChar);
AddColumn( Sell, "Sell", 1 );
AddColumn(IIf( Short, lastpriceShort, Null ) ,"Short",1.4,colorDefault,colorDefault,60);
AddColumn(IIf(Cover,lastpriceCover,Null),"Cover",1.4,colorDefault,colorDefault,60);
AddColumn(IIf(Cover,Ref(lastpriceshort,-1)-lastpriceCover,Null),"ShortPip",1.4,colorDefault,ColorShortProfit ,60);

AddColumn(BuyProfit,"Gain/Lose",1.4, colorBlack,colorYellow,60); // contains wining trades of every 2 lines
// all above are corect for gia BUY SELL sort cover

// AddColumn(ShortProfit ,"Short-kerdos/Zimia",1.4, colorBlack,colorOrange,60);
AddColumn(IIf(Sell,lastpriceSELL, Ref(lastpriceBuy,-1)),"Buy/Sell",1.4,colorDefault,colorBuyProfit ,60);
AddColumn(total ,"total",1.4,colorBrown,colorDefault,60);
AddColumn(((C-Ref(C,-1))/Ref(C,-1)*100),"% Change from Prior Close", 3.2, colorBlack,colorWhite); // %
AddSummaryRows( 1, 1.4, 4,7,12,13,15);
// } // end actionExplore


//--------------------- appearance of various signals of long / short in the chart
if( Status("Action")==actionIndicator )
{
SetChartBkColor(ParamColor("backround ",colorBlack));
SetChartOptions(0,chartShowArrows|chartShowDates);
strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);
Title1=Name() +","+Date()+","+ " TimeFrame: " + Interval(2)+"\n Open "+O +", High " +H +", Low "+L +", Close "+C+ ", "+"(" +WriteVal(ROC(C,1),1.2)+"%)" ;

Display_Bars = ParamToggle("Display Bars","No|Yes",1);
if (Display_Bars) Plot( C, "" , colorWhite, styleBar);
if (TradeTime) Plot( IIf(EA,6,-1e10),"",colorBlueGrey ,styleOwnScale|styleArea|styleNoLabel, -1, 90);

////////////////////// Arrows
belakiaBS = ParamToggle("Arrows Buy-Sell","HIDE|SHOW",1);
if( belakiaBS )
{
PlotShapes(IIf (Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-30);
PlotShapes(IIf (Sell,shapeDownArrow,shapeNone),colorRed,0,H,-40);
PlotShapes(IIf (Sell,shapeSmallCircle,shapeNone),colorRed,0,O,0);
}
belakiaSC = ParamToggle("Arrows Short-Cover","HIDE|SHOW",1);
if( belakiaSC )
{
PlotShapes(IIf(Short,shapeHollowSmallDownTriangle,shapeNone),colorYellow,0,H,-30);
PlotShapes(IIf(Cover,shapeHollowSmallUpTriangle,shapeNone),colorYellow,0,L,-40);
PlotShapes(IIf (Cover,shapeSmallCircle,shapeNone),colorYellow,0,O,0);
}

////////////////////// Sum Total buy and short positions
x=Cum(Buy); x1=Sum(BuyProfit,1000); x2=Sum(ShortProfit,1000);
// totalLS= IIf( Buy, lastpriceBuy, Null ) +IIf(Sell,lastpriceSELL,Null) );
TitleSynolo=" Total Pos Buy ="+x +"\n monodesLongShort "+total+ "\n Buy Profit Of " + x1+"\n Short Profit Of " + x2 + "\n Total = " + (x1-x2);

////////////////////// PlotText we appear gainers / lossers

for( i = 0; i < BarCount; i++ )
{
colorBuyProfit = IIf(BuyProfit>0,colorGreen,colorRed);
ColorShortProfit = IIf(ShortProfit >0,colorGreen,colorRed);
dist = TickSize*9;
TextPipsBS = ParamToggle("Plot Buy Pips","HIDE|SHOW",0);
if( TextPipsBS )
{
if( Buy ) PlotText( "Buy\n\n" + lastpriceBuy[ i ] /*+"\n "+WriteVal(shortProfit[ i ] ,1.4)*/ , i, L[ i ]-dist, colorBrightGreen ); //ColorShortProfit
if( Sell ) PlotText( "Sell\n"+lastpriceSELL[ i ] +"\n" + WriteVal(BuyProfit[ i ] ,1.4) , i, H[ i ]+dist, colorBlack,colorBuyProfit );
}
TextPipsSC = ParamToggle("Plot Short Pips","HIDE|SHOW",0);
if( TextPipsSC)
{
if( Short ) PlotText( "\n\n\nShort\n" + lastpriceShort[ i ], i, H[ i ]+dist, colorOrange );
if( Cover ) PlotText( "\n\n\nCover\n"+ lastpriceCover[ i ]+"\n"+WriteVal(ShortProfit [ i ],1.4), i, L[ i ]-dist, colorBlack, ColorShortProfit );
}
}

///////// END ///////////// PlotText we appear gainers / lossers

////////////////////// PlotText we appear the Time of the Trade
myDateTime = DateTime();
TextDateOnChart = ParamToggle("Plot Text Date Time","SHOW TextDate|HIDE TextDate",0);
if( TextDateOnChart )
for( i = 0; i < BarCount; i++ )
{
dist = 9;
if( Buy ) PlotText("\n\n\n"+NumToStr(myDateTime,formatDateTime) +"", i, H[ i ]-dist, colorLime );
if( Sell ) PlotText("\n\n\n"+NumToStr(myDateTime,formatDateTime)+"" , i, L[ i ]+dist, colorLime );
}

//////// END ////////////// PlotText we appear the Time of the Trade


Title=" # "+strWeekday+" # "+Title1 + TitleTradeTime+ "\n total ="+total +" monodesLong= "+monodesLong +" monadesShort= "+monadesShort+
"\n\n"+TitleSynolo ;

} // end actionIndicator



_SECTION_END();
 
Last edited:

Similar threads