Simple Coding Help - No Promise.

There is some alteration logic am trying to include in the code, but couldn't succeed. can any help me with my requirement.

Re-entry of order after the system exited a trade. For example, when short is initiated at 8000 and a maximum stop loss of 50 points hits at 8050, the system exits the trade. after a while if markets goes down below the entry point then short order should be initiated again.

can the above requirement be coded?

Code:
//SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorGold)+ "Jackpot system" + EncodeColor(colorRose)+" (" +  Name() + ") " + EncodeColor(colorGold)+ Interval(2) +
 "  " + Date() +" " +" •  Open "+WriteVal(O,1.2)+"  •  "+"Hi "+WriteVal(H,1.2)+"  •  "+"Lo "+WriteVal(L,1.2)+"  •  "+
"Close "+WriteVal(C,1.2)+" ("+WriteVal(C-Ref(C,-1),1,0)+" "+WriteVal((C-Ref(C,-1))*100/Ref(C,-1),1.1)+ "%)  •  Vol= "+ WriteVal(V,1.0)
 
);
SetPositionSize(1,spsShares);

_SECTION_BEGIN("System");
e= EMA(C,49);

//Conditions for Buying
Cond1 = ValueWhen(C,O<C);
Cond5 = e > Ref(e,-1);

//Conditions for Selling

Cond10 = e < Ref(e,-1);

e[BarCount-1]=Null;
e[BarCount-1]=Null;


Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
Buy =    Cond5 ;
Sell =    cond10    ;
Buy[BarCount-1]=Null;
Sell[BarCount-1]=Null;

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

BuyPrice=ValueWhen(Buy,C);

SellPrice=ValueWhen(Sell,C);

ShortPrice=ValueWhen(Short,C);

CoverPrice=ValueWhen(Cover,C);

StopLevel = 10;
ApplyStop( stopTypeLoss, stopModePoint, stoplevel, 1 );
Equity( 1, 0 ); // evaluate stops, all quotes

SetOption("EveryBarNullCheck", True );
Buystop = IIf( Buy, BuyPrice-Stoplevel , Null );
Shortstop = IIf( Short, ShortPrice+Stoplevel , Null );


Plot( Buystop, "Buystop", colorRed );
Plot( Shortstop, "Shortstop", colorGreen );

PlotShapes(IIf(Sell==2, shapeHollowCircle, shapeNone), colorYellow, 0,High, Offset=30);

PlotShapes(IIf(Cover==2, shapeHollowCircle, shapeNone), colorYellow, 0,Low, Offset=-30);


PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-20);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-30);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-25);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy);

BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
Edc=(
WriteIf (Buy AND Ref(shrt,-1), " BUY@ "+C+"  ","")+
WriteIf (Sell AND Ref(Long,-1), " SEll@ "+C+"  ","")+
WriteIf(Sell , "Last Trade Profit Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy  , "Last trade Profit Rs."+(SellPrice-C)+"","")+
WriteIf(Long AND NOT Buy, "Trade: Long Profit: "+WriteVal((C-BuyPrice))+"","")+
WriteIf(shrt AND NOT Sell, "Trade: Short Profit: "+WriteVal((SellPrice-C))+"",""));

dist = 3*ATR(10);
dist1 = 3*ATR(10);
for( i = 0; i < BarCount; i++ )
{
 if( Buy[i] )
 {
  PlotText( "\nBuy@:" + C[ i ], i, C[ i ]-dist[i], colorGreen, colorDarkOliveGreen );
 }
 if( Sell[i] )
 {
  PlotText( "Sell@:" + C[ i ], i, C[ i ]+dist1[i], colorRed, colorDarkOliveGreen );
 }
}
 

casoni

Well-Known Member
check this ,
2 options


Plot(C,"",3,132);
//------------- 1 -------------------
signalx = EMA(C,10)>EMA(C,12);
BuySetupValue=ValueWhen(signalx,H,1);
Plot(BuySetupValue,"",5,32);
buy=Cross(C,BuySetupValue);
PlotShapes(Buy*1,5,0,L,-10);


//--------------- 2 --------------
signalx = Cross(EMA(C,10),EMA(C,12));
BuySetupValue=ValueWhen(signalx,H,1);
Plot(BuySetupValue,"",6,32);
buy=Cross(C,BuySetupValue);
PlotShapes(Buy*1,6,0,L,-15);
 

Dawood

Active Member
Dear Friends , I need this afl to take only the values of open high low and close of previous day from 3.00 pm to 3.30 pm. Please help.

Quote:
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_BEGIN("BSP");
function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}

O1 = SelectedValue( TimeFrameGetPrice( "O", inHourly, -1 ));
H1=SelectedValue( TimeFrameGetPrice( "H", inHourly, -1 ));
L1=SelectedValue( TimeFrameGetPrice( "L", inHourly, -1 ));
C1 = SelectedValue( TimeFrameGetPrice( "C", inHourly, -1 ));

bu1 = (C1-L1)+C1;
se2 = C1-(H1-C1);
PP = (H1 + L1 + C1 + O1) / 4 ;
R1 = (2 * PP) - L1;
S1 = (2 * PP) - H1;
R2 = PP + R1 - S1;
S2 = PP + S1 - R1;
R3 = R2 + (R1 - PP);
S3 = S2 - (PP - S1);

Plot (se2,"Sell Pressure",32,4);
Plot (bu1,"Buy Pressure",27,4);

_SECTION_END();
O1-H1-L1-C1 must be the values of open high low and close of previous day from 3.00 pm to 3.30 pm only.
Somebody please help if possible.
 
check this ,
2 options


Plot(C,"",3,132);
//------------- 1 -------------------
signalx = EMA(C,10)>EMA(C,12);
BuySetupValue=ValueWhen(signalx,H,1);
Plot(BuySetupValue,"",5,32);
buy=Cross(C,BuySetupValue);
PlotShapes(Buy*1,5,0,L,-10);


//--------------- 2 --------------
signalx = Cross(EMA(C,10),EMA(C,12));
BuySetupValue=ValueWhen(signalx,H,1);
Plot(BuySetupValue,"",6,32);
buy=Cross(C,BuySetupValue);
PlotShapes(Buy*1,6,0,L,-15);

Thanks a lot....:):hug:
 

casoni

Well-Known Member
Code:
Stime  =150000;
Etime = 153000;
TN = TimeNum();
ST =  TN == Stime ;
ET =  TN == Etime ;
BS = ValueWhen ( ST, Cum(1)-1);
BE = ValueWhen ( ET, Cum(1)-1);
Bar = BE - BS; 
SO = ValueWhen ( ST , O );
SH = ValueWhen ( ET , HHV ( H, Bar ) );
SL = ValueWhen ( ET , LLV ( L, Bar ) );
SC = ValueWhen ( ET , C );
 

Plot(C,"",3,132);

//Plot(SO, "", colorPaleBlue,24 +styleNoRescale + styleNoLabel );
//Plot(SH, "", colorBlue,24+ styleNoRescale + styleNoLabel );
//Plot(SL, "", colorGreen,24 + styleNoRescale + styleNoLabel );
//Plot(SC, "", colorRed, 24 + styleNoRescale + styleNoLabel );

O1=SO;
H1=SH;
L1=SL;
C1=SC;

bu1 = (C1-L1)+C1;
se2 = C1-(H1-C1);
PP = (H1 + L1 + C1 + O1) / 4 ; 
R1 = (2 * PP) - L1; 
S1 = (2 * PP) - H1; 
R2 = PP + R1 - S1; 
S2 = PP + S1 - R1; 
R3 = R2 + (R1 - PP); 
S3 = S2 - (PP - S1); 
Plot (se2,"Sell Pressure",32,4);
Plot (bu1,"Buy Pressure",27,4);
 
Code:
Stime  =150000;
Etime = 153000;
TN = TimeNum();
ST =  TN == Stime ;
ET =  TN == Etime ;
BS = ValueWhen ( ST, Cum(1)-1);
BE = ValueWhen ( ET, Cum(1)-1);
Bar = BE - BS; 
SO = ValueWhen ( ST , O );
SH = ValueWhen ( ET , HHV ( H, Bar ) );
SL = ValueWhen ( ET , LLV ( L, Bar ) );
SC = ValueWhen ( ET , C );
 

Plot(C,"",3,132);

//Plot(SO, "", colorPaleBlue,24 +styleNoRescale + styleNoLabel );
//Plot(SH, "", colorBlue,24+ styleNoRescale + styleNoLabel );
//Plot(SL, "", colorGreen,24 + styleNoRescale + styleNoLabel );
//Plot(SC, "", colorRed, 24 + styleNoRescale + styleNoLabel );

O1=SO;
H1=SH;
L1=SL;
C1=SC;

bu1 = (C1-L1)+C1;
se2 = C1-(H1-C1);
PP = (H1 + L1 + C1 + O1) / 4 ; 
R1 = (2 * PP) - L1; 
S1 = (2 * PP) - H1; 
R2 = PP + R1 - S1; 
S2 = PP + S1 - R1; 
R3 = R2 + (R1 - PP); 
S3 = S2 - (PP - S1); 
Plot (se2,"Sell Pressure",32,4);
Plot (bu1,"Buy Pressure",27,4);
nice codings
 
i have some doubts casoni sir

first doubt how to get the profit and loss of the last two trades (not current trade)


second doubt

i want to add two conditions for buy

if price change is above 2%
i want to use one condition

if price change is less than 2% i want different buy condition

thank you
 

casoni

Well-Known Member
Last edited:

Similar threads