Simple Coding Help - No Promise.

Joined
Mar 20, 2008
Messages
74
Likes
34
Hi abhishekji,

The follg. is the image of the afl done by you for cubtji. http://i.imgur.com/gJYygHC.png

I have modified the code a bit, with respect to OHLC and now getting the Buy,sell,cover short values correctly. Plots also accurate.

The only issue is when scanning at different timeframe, it produces diff result. i.e. it omits certain results in certain tf and includes some result. How it can be rectified?

And also I want to plot the words "buy/sellbought " in the chart area visible w/o zoom in /zoom out. How it can be done?
Pls help for this too.

Regards,
 
Joined
Mar 20, 2008
Messages
74
Likes
34
It depends on the time frame actually. You can however add another parameter to the distance part and manage it as per your convenience (in the for loop).
Hi,

Can you tell me why? Bcoz yesterdays OHLC and todays open remains the same in all tfs. Only high/low changes. If it changes SL will b executed.

So IMO it shd remain the same in all tfs. Pls clarify.

Regards,
 
Joined
Nov 28, 2012
Messages
167
Likes
79
Location
Kolkata
Great, abhig! I didn't expect that someone would write a rather complete code so quickly just to help. No thanks can match your good intent.

I will copy your code into the few lines I have written and get back here. I could not find the SL part in your code but perhaps can manage by following your given code.

Just awesome!:thumb:
 
Joined
Mar 20, 2008
Messages
74
Likes
34
I have taken Close of candle as buyprice, shortprice, sellprice and coverprice. So each candle has different close price in different timeframes. You can however change them to Y's high/low or open or anything that you like.

And my answer was in respect to your other code that you want to be able to see the text without zooming in/out. For that you can add a parameter and change it according to suit you.

okay. understood.

Yes ji. I hv changed Y's high/low respectively and able to see the values in the chart correctly. But while scanning, the results r not the same in all tfs. That's the glitch now.

Regards,
 
Joined
Mar 20, 2008
Messages
74
Likes
34
Pass the code. Will you?
Sure. Here it is.
Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Trading signals");
NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0);
Plot(NewDay, "", 47, 2 + 32768 + 4096, Minvalue = 0, Maxvalue = 1);
StartTime	= ParamTime("Start time", "09:15");
CloseTime	= ParamTime("Closing Time", "15:20");
GapFix		= Param("Minimum stop loss", 0.015, 0, 1, 0.05);
GapFix1	= GapFix/100;

HighY	= TimeFrameGetPrice("High", inDaily, -1);
LowY	= TimeFrameGetPrice("Low", inDaily, -1);

OpenD	= TimeFrameGetPrice("Open", inDaily);
//LowD	= TimeFrameGetPrice("Low", inDaily);
//HighD	= TimeFrameGetPrice("High", inDaily);
xFilter	= BarsSince(Cross(High, HighY))>BarsSince(NewDay) OR BarsSince(Cross(LowY, Low))>BarsSince(NewDay);
LowD	= ValueWhen(xFilter, LowestSince(NewDay, Low));
HighD	= ValueWhen(xFilter, HighestSince(NewDay, High));


Plot(HighY, "Y's H ", ParamColor("Y's High Color", colorYellow), ParamStyle("Y's High Style", styleDashed));
Plot(LowY, "Y's L ", ParamColor("Y's Low Color", colorYellow), ParamStyle("Y's Low Style", styleDashed));
Plot(OpenD, "Day's O ", ParamColor("Day's Open Color", colorRed), ParamStyle("Day's Open Style", styleDashed));
Plot(LowD, "Day's L ", ParamColor("Day's Low Color", colorGreen), ParamStyle("Day's Low Style", styleDashed));
Plot(HighD, "Day's H ", ParamColor("Day's High Color", colorGreen), ParamStyle("Day's High Style", styleDashed));

// Filter time, low and high conditions
Conds		= TimeNum()>StartTime AND TimeNum()<CloseTime AND (OpenD*(1+GapFix1))<HighY AND (OpenD*(1-GapFix1))>LowY;

Buy		= Conds AND OpenD==LowD AND Cross(High, HighY);
Sell	= Cross(TimeNum(), CloseTime) OR Cross(OpenD, Low);
Short	= Conds AND OpenD==HighD AND Cross(LowY, Low);
Cover	= Cross(TimeNum(), CloseTime) OR Cross(High, OpenD);

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

BuyPrice		= ValueWhen(Buy, HighY); 
ShortPrice		= ValueWhen(Short, LowY);
CoverPrice		= ValueWhen(Cover, OpenD);
SellPrice		= ValueWhen(Sell, OpenD);


dist	= 1.5*ATR(10);
for (i=0; i<BarCount; i++) {
	if (Cover[i]) {
		PlotText( "\nCover short: " + CoverPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
		PlotText( "\n\nProfit: " + (ShortPrice[i]-CoverPrice[i]), i+1.5, L[ i ]-dist[i]-3, colorLime);
	} else if (Sell[i]) {
		PlotText( "\nSell bought: " + SellPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
		PlotText( "\n\nProfit: " + (SellPrice[i]-BuyPrice[i]), i+1.5, H[ i ]+dist[i]+5, colorOrange);
	}
	if(Buy[i]) {
		PlotText( "Buy: " + BuyPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
	} else if( Short[i]) {
		PlotText( "Short: " + ShortPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
 	}
}

PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low, -28);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High, -28);
PlotShapes(Cover*shapeHollowUpArrow, colorGreen, 0, Low, -45);
PlotShapes(Sell*shapeHollowDownArrow, colorRed, 0, High, -45);

printf("\nSignal came " + IIf(BarsSince(Short)>BarsSince(Buy), BarsSince(Buy), BarsSince(Short)) + " bars ago");
WriteIf(BarsSince(Short)>BarsSince(Buy), "\nBuy@ " + BuyPrice, "\nShort@ " + ShortPrice);

printf("\nPossiblities ");
printf("\nMax Profit: " + IIf(BarsSince(Short)>BarsSince(Buy), (HighD-BuyPrice), (ShortPrice-LowD)));
printf("\nMin Profit: " + IIf(BarsSince(Short)>BarsSince(Buy), (OpenD-BuyPrice), (ShortPrice-OpenD)));


// Write Messages
printf("\n\nLet the profit run.");
printf("\nClose a call only when trailing SL hits");
_SECTION_END();
 
Joined
Nov 28, 2012
Messages
167
Likes
79
Location
Kolkata
@ abhi

Just added the signals! A bit confused! The exits seem to work by (reverse) crossovers only, not TSL. Wanted to add the code here but have forgotten how to. Also blocked out the short code to keep just the buy-sell. But all signals except the 1st buy vanished. In one or two cases, however, the TSL seems to work.

Kindly have a look if possible.
 
Last edited:
Joined
Mar 20, 2008
Messages
74
Likes
34
You are closing all your calls at the open price of the day.

This would give you the open price in case the stop loss hits and Close of the candle otherwise.

Code:
BuyPrice		= ValueWhen(Buy, HighY); 
ShortPrice		= ValueWhen(Short, LowY);
CoverPrice		= ValueWhen(Cover, iif(Cross(High, OpenD), openD, close));
SellPrice		= ValueWhen(Sell, iif(Cross(OpenD, Low), OpenD, close) );
Thank you so much. realised the mistake. but it shows the close at 3.30. Practically, trades r auto squared off at 3.20pm. So it is good to change the close to close of 3.20pm.

I do not know how to do it.:confused:
 
Joined
Nov 28, 2012
Messages
167
Likes
79
Location
Kolkata
@ abhig

After a few tweaks with the EMA periods the TSL picture is clearer. TSL seems to work which was perhaps not easy to detect for me with fast EMAs. :clapping:


Will try to add the SL as well and report here.
 
Joined
Jan 22, 2014
Messages
37
Likes
36
I am creating a real time scanner which shows the stock higher high and lower low in realtime .
i.e. stocks which are braking its day high and vice versa in realtime say 30sec or 1 min
As per my understanding I have written the code .

Filter=1;
BULL1="BULL";
BEAR1="BEAR";
TH=TimeFrameGetPrice( "H", inDaily, 0 );
TL=TimeFrameGetPrice( "L", inDaily, 0 );
Status1= WriteIf(H>Ref(TH,-1),"BULL",WriteIf(L<Ref(TL,-1),"BEAR","NOTREND"));
MSG=WriteIf(Status1=="BULL","AT THE HIGH OF THE DAY =>"+TH + "PREVIOUS HIGH CAME=> " +Ref(TH,-1)+" @ Time "+ValueWhen(Ref(TH,-1),DateTime()),"AT THE LOW OF THE DAY =>"+TL + "PREVIOUS LOW CAME=> " +Ref(TL,-1)+" @ Time "+ValueWhen(Ref(TL,-1),DateTime()));
AddColumn( TH, "Todays High", 1.2 );
AddColumn( TL, "Todays LOW", 1.2 );
AddColumn( C, "Last Rate", 1.2 );
AddTextColumn(Status1,"Trend1",1,IIf(Status1=="BULL",colorGreen,colorRed) );
AddTextColumn(MSG,"Message",1,IIf(Status1=="BULL",colorGreen,colorRed) );


Its not showing correctly .Any help appreciated
 

Similar threads

Broker Special Offers