Simple Coding Help - No Promise.

Hi seniors, Please help me. This is the complete formula But I am facing one problem in this formula.
Buy signal is generating Short side Please remove Buy signal from Short side.
I have tried but failed so kindly help me seniors.

(Please note I have written 5 Buy conditions in this formula Please don't change)


_SECTION_BEGIN("Realtimetips ");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorBlack , styleNoTitle | styleCandle | GetPriceStyle() );
//
messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

if (showsl == 0)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}
exitlong = Cross(s5d, C);
//PlotShapes(exitlong * shapeDownArrow, colorRed,0,H,-20);
exitshort = Cross(C,s5d);
//PlotShapes(exitshort * shapeUpArrow, colorGreen,0,L,-20);


Buy = exitshort;
Sell = exitlong;
Short = exitlong;
Cover = exitshort;


//AlertIf( Buy, "", "BUY @ " + C, 1 );
//AlertIf( Sell, "", "SELL @ " + C, 2 );


for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = s5d;


Buy0 = entry + (entry * .05);
tar0 = entry + (entry * .10);
tar1 = entry + (entry * .15);
tar2 = entry + (entry * .30);
tar3 = entry + (entry * .45);
tar4 = entry + (entry * 0.60);


StopLoss1 = entry - (entry * .10);
StopLoss2 = entry - (entry * .20);





bars = i;
i = 0;
}


if(Sell == 1)
{
sig = "Sell";





entry = C;
sl = s5d;
Buy0 = entry - (entry * .05);
tar0 = entry - (entry * .10);
tar1 = entry - (entry * .15);
tar2 = entry - (entry * .30);
tar3 = entry - (entry * .45);
tar4 = entry - (entry * 0.60);


StopLoss1 = entry - (entry * .10);
StopLoss2 = entry - (entry * .20);






bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorOrange);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];


Plot(LineArray(bars-Offset, StopLoss1, BarCount, StopLoss1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, StopLoss2, BarCount, StopLoss2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);


Plot(LineArray(bars-Offset, Buy0, BarCount, Buy0,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar0, BarCount, tar0,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar4, BarCount, tar4,1), "", Clr, styleLine|styleDots, Null, Null, Offset);


Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorCustom14, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorTurquoise, styleLine|styleDots, Null, Null, Offset);


for (i=bars; i <BarCount;i++)
{
PlotText("" + sig + " @ " + entry, BarCount+3, entry, Null, colorTurquoise);
PlotText("StopLoss1 : @ " + StopLoss1, BarCount+3, StopLoss1, Null, Clr);
PlotText("StopLoss2 : @ " + StopLoss2, BarCount+3, StopLoss2, Null, Clr);


PlotText("Buy0 : @ " + Buy0, BarCount+3, Buy0, Null, Clr);
PlotText("Target 0 : @ " + tar0, BarCount+3, tar0, Null, Clr);
PlotText("Target 1 : @ " + tar1, BarCount+3, tar1, Null, Clr);
PlotText("Target 2 : @ " + tar2, BarCount+3, tar2, Null, Clr);
PlotText("Target 3 : @ " + tar3, BarCount+3, tar3, Null, Clr);
PlotText("Target 4 : @ " + tar4, BarCount+3, tar4, Null, Clr);


PlotText("Trailing SL @ " + sl, BarCount+3, sl, Null, colorCustom14);
}
//Plot(sl, "", colorCustom14, styleLine);





/////////////M
//GfxRectangle(pxw/2,1,(pxw/2)-5,pxh);


BarB = BeginValue(BarIndex());//Beginvalue of Barindex
BarE = EndValue(BarIndex());//EndValue of Barindex
BarC = BarIndex();//Current Barindex
BarL = LastValue(BarC,1);//LastValue of Barindex
BarT = BarIndex() - Nz(ValueWhen(Day()!= Ref(Day(),-1) ,BarIndex()),0) ;


TrdBegin = ParamTime("Trading Begin Time","09:15",0);
TrdEnd = ParamTime("Trading End Time","15:10",0);
SqOff = ParamTime("Square Off Time","15:14",0);


Lossp = Param("Loss Percentage",20.0,0.05,20,0.05)/100;// 20% Final// Lossp = Param("Loss Percentage",0.6,0.05,20,0.05)/100;
Profitp = Param("Profit Percentage",10.0,0.05,20,0.05)/100;


BuyPrice = ValueWhen(Buy,C);
ShortPrice = ValueWhen(Short,C);//short


BuySL = BuyPrice - (BuyPrice*Lossp);
ShortSL = ShortPrice + (ShortPrice*Lossp);


Buy0 = BuyPrice + (BuyPrice*Profitp);
Short0 = ShortPrice - (ShortPrice*Profitp);


////////////////////////////////
//Buy set 1 perfect


Buy1 = Cross(exitshort,0) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Buy2 = Cross(exitshort,0) OR Cross(Buy0,C) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Buy3 = Cross(exitshort,0) OR Cross(tar0,C) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Buy4 = Cross(exitshort,0) OR Cross(tar1,C) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;
Buy5 = Cross(exitshort,0) OR Cross(tar2,C) AND TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;


Buy = Buy1 = Buy2 = Buy3 = Buy4 = Buy5;//Final
//Buy = Buy1 AND Buy2 AND Buy3 AND Buy4 AND Buy5;
//Buy = Buy1 OR Buy2 OR Buy3 OR Buy4 OR Buy5;


Sell = Cross(C,Short) OR Cross(BuySL,C) OR Cross(Buy,C) OR Cross(Buy1,C) OR Cross(StopLoss1,C) OR Cross(StopLoss2,C) OR Cross(tar0,C) OR Cross(tar1,C) OR Cross(tar2,C) OR Cross(tar3,C) OR Cross(tar4,C) OR TimeNum() >= SqOff;


Buytmp=Cross(Buy,0);
Buy = IIf(Ref(Buytmp, -1),1,0);


Selltmp=Cross(Sell,0);// this is required don't ignore
Sell = IIf(Ref(Selltmp, -1),1,0);



//Short Condition
Short = Cross(exitlong,0) OR TimeNum() >= TrdBegin AND TimeNum() <= TrdEnd;


Cover = Cross(Buy,C) OR Cross(C,ShortSL) OR Cross(tar0,C) OR Cross(tar1,C) OR Cross(C,tar2) OR Cross(C,tar3) OR Cross(C,tar4) OR TimeNum() >= SqOff;;//

Shorttmp=Cross(Short,0);
Short = IIf(Ref(Shorttmp, -1),1,0);


Covertmp=Cross(Cover,0);// this is required don't ignore
Cover = IIf(Ref(Covertmp, -1),1,0);




//testing
Buy = IIf(Ref(Sum(Buy,BarT),-1)==0,Buy,ExRem(Buy,Sell)); //Don't change setting
Sell = IIf(Ref(Sum(Sell,BarT),-1)==0,Sell,ExRem(Sell,Buy));



Short = IIf(Ref(Sum(Short,BarT),-1)==0,Short,ExRem(Short,Cover));
Cover = IIf(Ref(Sum(Cover,BarT),-1)==0,Cover,ExRem(Cover,Short));


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


PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorYellow, 0,L, Offset=-30);
//PlotShapes(IIf(Buy2, shapeUpArrow, shapeNone),colorYellow, 0,L, Offset=-30);
//PlotShapes(IIf(Buy3, shapeUpArrow, shapeNone),colorBlue, 0,L, Offset=-50);


PlotShapes(IIf (Sell, shapeCircle, shapeNone),colorRed);
//PlotShapes(IIf(Sell2, shapeCircle, shapeNone),colorYellow, 0,L, Offset=-35);
//PlotShapes(IIf(Sell3, shapeCircle, shapeNone),colorBlue, 0,L, Offset=-50);
 
Last edited:

Romeo1998

Well-Known Member
Sir @sharad17
I downloaded data for ACC cash n future n checked from 1st jan 2020 to 28th apr 2020 with Daily periodicity...
i am getting only 1 result of date 2nd jan 2020...
Sir you might have changed something in code... :)
 

Attachments

Sit @Romeo1998

Just changed _F1 to -I , thats it , here's the code in which i have changed
//https://www.traderji.com/community/threads/simple-coding-help-no-promise.90119/page-610
//Romeo1998
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = " Romeo1998 " + StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Plot(Close,"",IIf(O==H,4,IIf(O==L,5,1)),styleCandle);
list0 = CategoryGetSymbols( categoryWatchlist, 0 ); // List contains cash scripts
list1 = CategoryGetSymbols( categoryWatchlist, 1 ); // List contains futures scripts
cash_bull=cash_bear=future_bull=future_bear=0;
for(i = 0; (sym1 = StrExtract(list0, i)) != ""; i++)
{
SetForeign(sym1) ;
cash_bull=O==L;
cash_bear=O==H;
for(j = 0; (sym2 = StrExtract(list1, j)) != ""; j++)
{
if(sym2 == sym1+"-I")
{
SetForeign(sym2) ;
future_bull=O==L;
future_bear=O==H;
RestorePriceArrays( );
}
}
RestorePriceArrays( );
}
bullish=cash_bull AND future_bull ;
bearish=cash_bear AND future_bear;
Filter =( InWatchList( 0 ) OR InWatchList( 1 ) ) AND ( bullish OR bearish ) AND StrFind(Name(),"-I")==0;

AddColumn( IIf( bullish, C, Null ), "Bullish C (cash)", 1.2, 27 );
AddColumn( IIf( bullish, o, Null ), "O (cash)", 1.2, 27 );
AddColumn( IIf( bullish, l, Null ), "L (cash)", 1.2, 27 );
AddColumn( IIf( bullish, Foreign(Name()+"-I","C"), Null ), "Bullish C (future)", 1.2, 27 );
AddColumn( IIf( bullish, Foreign(Name()+"-I","O"), Null ), "O (future)", 1.2, 27 );
AddColumn( IIf( bullish, Foreign(Name()+"-I","L"), Null ), "L (future)", 1.2, 27 );

AddColumn( IIf( bearish, C, Null ), "Bearish C (cash)", 1.2, 4 );
AddColumn( IIf( bearish, o, Null ), "O (cash)", 1.2, 4 );
AddColumn( IIf( bearish, h, Null ), "H (cash)", 1.2, 4 );
AddColumn( IIf( bearish, Foreign(Name()+"-I","C"), Null ), "Bearish C (future)", 1.2, 4 );
AddColumn( IIf( bearish, Foreign(Name()+"-I","O"), Null ), "O (future)", 1.2, 4 );
AddColumn( IIf( bearish, Foreign(Name()+"-I","H"), Null ), "H (future)", 1.2, 4 );
please take a look , i am checking on EOD
Many Thanks for supporting .. Highly Obliged
 
Last edited:
hi sir, can u plz help with identifying the below error..

The problem is i am getting to many buy order until the candle closes. I use 1 min for trading and the buy orders keep on poping up until the open of next candle... Hence, plz help me to fix it....
 

Attachments

hi sir, can u plz help with identifying the below error..

The problem is i am getting to many buy order until the candle closes. I use 1 min for trading and the buy orders keep on poping up until the open of next candle... Hence, plz help me to fix it....
Code is way too long (750+ lines) for anyone to deal with it....
Also it very badly written....

Do not trade with real money or do so at your own risk.....
 

Similar threads