Simple Coding Help - No Promise.

Code:
_SECTION_BEGIN("Price");
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", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

TimeFrameSet(in1Minute*30);	
	HTFMA = MA(Close,200);	
	HTFUP = Close > HTFMA;
	HTFDN = Close < HTFMA;
TimeFrameRestore();
HTF_MA = TimeFrameExpand(HTFMA,in1Minute*30);
HTF_UP = TimeFrameExpand(HTFUP,in1Minute*30);
HTF_DN = TimeFrameExpand(HTFDN,in1Minute*30);
MA200  = MA(Close,200);
Buy   = Close > MA200 AND HTF_UP; 	
Sell  = Close < MA200;
Buy   = ExRem(Buy,Sell);						
Sell  = ExRem(Sell,Buy);
Short = Close < MA200 AND HTF_DN; 	
Cover = Close > MA200;
Short = ExRem(Short,Cover);						
Cover  = ExRem(Cover,Short);
SetPositionSize(1,4);	
Plot(HTF_MA,"30MIN_MA200",IIf(HTF_UP,colorBlue,colorRed),styleThick|styleNoRescale);
Plot(MA200,"MA200",IIf(C>MA200, colorBlue,colorRed),styleLine);
PlotShapes(Buy+2*Short,colorWhite,0,IIf(Buy,L,H));
PlotShapes(Cover*3+4*Sell,colorWhite,0,IIf(Cover,L,H));
_SECTION_END();
hi..
When i changed the timeframe to 1min...i get only one MA. Uts working fine in 5mins TF.
 
hi..
When i changed the timeframe to 1min...i get only one MA. Uts working fine in 5mins TF.
Code:
Plot(HTF_MA,"30MIN_MA200",IIf(HTF_UP,colorBlue,colorRed),styleThick|styleNoRescale);
The plot uses styleNoRescale to avoid compression of chart . . .

remove i.e. delete |styleNoRescale from the above line . . . . to see both even if the HTF MA value is far away

Code:
Plot(HTF_MA,"30MIN_MA200",IIf(HTF_UP,colorBlue,colorRed),styleThick);
:) Happy
 

XRAY27

Well-Known Member
Use ValueWhen for getting the price at which Buy/Sell happens . . .

after that just apply your % values . . .

An example where ValueWhen was used is already there in this thread . . .



:) Happy

_SECTION_BEGIN("Price");
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", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("25");
MO=EMA(C,10);
ML=EMA(C,34);


Plot(MO,"",colorBlue,styleDashed);
Plot(ML,"",4,styleDashed);

Buy = Cross (MO,ML);
Sell = Cross (ML,MO);
BuyPrice=ValueWhen(Buy,H);
SellPrice=ValueWhen(Sell,L);

sig = "BUY";
tar1 =Buy + (Buy * .0038);


sig = "SELL";
tar1 = Sell - (Sell * .0038);

dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy " + H[ i ], i, H[ i ]-dist,2, colorGreen );
if( Sell ) PlotText( "SELL " + L[ i ], i, L[ i ]+dist, colorRed, colorYellow );
}

PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorYellow, colorYellow ) );
AlertIf(Cross(MO,ML), "SOUND C:\\Windows\\Media\\Ringin.wav", "BUY", 2 );
AlertIf(Cross(ML,Mo), "SOUND C:\\Windows\\Media\\Ringin.wav","SELL", 2 );



_SECTION_END();

please add line to tar1
 
please add line to tar1

Code:
_SECTION_BEGIN("Price");
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", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("25");
MO=EMA(C,10);
ML=EMA(C,34);

Plot(MO,"",colorBlue,styleDashed);
Plot(ML,"",4,styleDashed);

Buy =  Cross (MO,ML);
Sell = Cross (ML,MO);

dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "Buy " + H[ i ], i, H[ i ]-dist[i],2, colorGreen );
if( Sell[i] ) PlotText( "SELL " + L[ i ], i, L[ i ]+dist[i], colorRed, colorYellow );
}

PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorYellow, colorYellow ) );
AlertIf(Cross(MO,ML), "SOUND C:\\Windows\\Media\\Ringin.wav", "BUY", 2 );
AlertIf(Cross(ML,Mo), "SOUND C:\\Windows\\Media\\Ringin.wav","SELL", 2 );


myBuyPrice=ValueWhen(Buy,H);
mySellPrice=ValueWhen(Sell,L);
Long = BarsSince(Buy) < BarsSince(Sell);
Target = IIf(Long, myBuyPrice * (1 + .0038), mySellPrice * (1 - .0038));
Plot(Target,"",IIf(Long,colorBlueGrey,colorLime),styleDashed|styleStaircase);
_SECTION_END();
:) Happy
 
bump... if anyone could help..

Did a bit of modification in the codes and the present code is like this

Code:
_SECTION_BEGIN("Price");
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", ParamColor("Color", colorDefault ), 

styleThick | ParamStyle("Style") | GetPriceStyle() ); 

_SECTION_END();
 
 
_SECTION_BEGIN("ema_crossover");
//by Chandraprakash, [email protected]// 
x = EMA(Close,6);
y = EMA(Close,30);
Plot(EMA(Close,6),"",colorYellow,styleThick);
Plot(EMA(Close,30),"",colorWhite,styleThick);
 
Crossup = Cross(x,y);
Buy=Crossup;
EnterLong = ValueWhen(Buy, High);
PlotShapes(shapeUpArrow*Buy,colorYellow,0,L);
GfxSelectFont("Times New Roman", 16, 700, True ); 
Title = Name() + " " + Date()+" " + EncodeColor( colorWhite 

) +"6/30 EMA " +EncodeColor( colorWhite )
+ " O " + O + " H " + H + " L " + L + " C "+ C + "\n";

Crossdown = Cross(y,x);
Sell=Crossdown;
Entershort = ValueWhen(Sell, L);
PlotShapes(shapeDownArrow*Sell,colorWhite,0,H);
Title = Name() + " " + Date()+" " + EncodeColor( colorWhite 

) +"6/30 EMA " +EncodeColor( colorWhite )
+ " O " + O + " H " + H + " L " + L + " C "+ C + "\n";

IIf(((EMA(Close, 6))>(EMA(Close, 30))),GfxTextOut("Buy Above " +EnterLong , 25 , 25 ),GfxTextOut("Sell Below " +Entershort, 25 , 50 ));

_SECTION_END();

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",40,11,100,1);
GfxSelectFont("calibri", FS, 700, True ); 
GfxSetBkMode( colorWhite );  
GfxSetTextColor( ParamColor("Color",colorWhite) ); 
Hor=Param("Horizontal Position",1040,1,1200,1);
Ver=Param("Vertical Position",1,1,830,1); 
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("calibri", 13, 700, True ); 
GfxSetBkMode( colorWhite );  
GfxSetTextColor(ParamColor("Color",colorWhite) ); 
GfxTextOut("Change: "+DD+"  ("+xx+"%)", Hor-15 , Ver+60 );
_SECTION_END();
The problem is that I am unable to bring out only the last signal, it is presently showing both the signals Buy above and the sell below (Have a look at the attached image file..) and also I am unable to calculate the stop loss I need a stop loss value visible on the chart just like the entry price is.. The stop loss should be a high/low of the previous swing / 5 bars..



Regards
 
Dear Happy Singh ji,

Thanks it worked awesome, Can you please help me how to print the stoploss value just like the entry price, the stoploss should be the highest high of previous 5 bars and viceversa for the low.. Thanks again for helping a newbie like me...

Try this


Code:
Long = BarsSince(Buy) < BarsSince(Sell);

myString = WriteIf(Long, "Sell Below " + Entershort, "Buy Above " +EnterLong);

GfxTextOut(myString, 25 , 25 )

:) Happy
 
Dear Happy Singh ji,

Thanks it worked awesome, Can you please help me how to print the stoploss value just like the entry price, the stoploss should be the highest high of previous 5 bars and viceversa for the low.. Thanks again for helping a newbie like me...
Now you should be able to do it your self :thumb:

psedu-code // Logic

Long SL = valuewhen(Buy, Ref(LLV(L,5),-1)); and
Short SL = valuewhen(Sell, Ref(HHV(H,5),-1));

:) Happy
 

Similar threads