Simple Coding Help - No Promise.

momin02

Member
Hi seniors, Please help me. This is the complete formula But I am facing one problem in this formula.
I have tried but failed so kindly help me seniors.

_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);

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

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

for(i=BarCount-1;i>1;i--)
{
{
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;
}

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, 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("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) ;

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;

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

ShortSL = ShortPrice + (ShortPrice*Lossp);

Short0 = ShortPrice - (ShortPrice*Profitp);

////////////////////////////////

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;

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

//Short Condition

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

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

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

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
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

• 28.7 KB Views: 28

New Member
Sit @Romeo1998

Just changed _F1 to -I , thats it , here's the code in which i have changed
//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:

deepakg2009

New Member
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

• 26.2 KB Views: 26

mastermind007

Well-Known Member
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....

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

Happy_Singh

Happy
Not sure how it will be useful, but if you want to try
use styleNoRescale in the plot statement

.