Simple Coding Help - No Promise.

Guyss... Need a small modification on the below code. Its ORB strategy, after the initial 5 minutes, based on the breakout/breakdown it shows signal.

However, i would like to add the below condition.

1. we go long when opening range high is broke with opening range low as stop loss.

when stop loss hits, the system exits the position. But I want to reverse the trade, by exiting the long position and going short with opening range high as stop loss, when this trade's stop loss hit, we should exit the trade, no more trades.

2. we go short when opening range low is broke with opening range high as stop loss.

when stop loss hits, the system exits the position. But I want to reverse the trade, by exiting the short position and going long with opening range low as stop loss, when this trade's stop loss hit, we should exit the trade, no more trades.

code:
Code:
function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}




_SECTION_BEGIN("Augubhai's ORB System v1.1"); 

//--Intraday time frame 
TimeFrameSet(in5Minute); //If reseting, check formula for TimeFrameInMinutes 
TimeFrameInMinutes = 5;

//--Define all params 
EntryBufferPct = ParamOptimize("Entry Buffer %", 0, 0, 0, 0);
SLPct = ParamOptimize("SL %", 0, 0, 0, 0);
TargetPct = ParamOptimize("Target %", 0, 0, 0, 0);
MaxTarget = 100;
TargetPct = IIf(TargetPct == 0, MaxTarget, TargetPct); 
EntryTimeStart = ParamOptimize("Entry Time Start (Minutes)", 5, 5, 120, 5);
EntryBarStart = floor(EntryTimeStart/TimeFrameInMinutes) - 1;
EntryTimeEnd = ParamOptimize("Entry Time End (Minutes)", 425, 10, 180, 5);
EntryBarEnd = floor(EntryTimeEnd/TimeFrameInMinutes) - 1;
EntryBarEnd = IIf(EntryBarEnd < EntryBarStart, EntryBarStart, EntryBarEnd);  

//--Plot Price Candle Chart
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 | GetPriceStyle() ); 

//--New Day & Time. End Day & Time . End Day & Time is null till end of day 1  
NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0; 
printf("\n NewDay  : " + NewDay ); 
EndDay = (Day()!= Ref(Day(), 1)); 
printf("\n EndDay  : " + EndDay );
FirstBarTime = ValueWhen(NewDay,TimeNum(),1); 
EndTime = ValueWhen(EndDay,TimeNum(),1);
SquareOffTime = 152000;

//--Calculate ORB, and SL
HighestOfDay = HighestSince(NewDay,H,1); 
LowestOfDay = LowestSince(NewDay,L,1); 
BarsSinceNewDay = BarsSince(NewDay);
ORBH = ValueWhen(BarsSinceNewDay<=EntryBarStart,HighestOfDay ,1) * (1 + (EntryBufferPct/100)); 
ORBL = ValueWhen(BarsSinceNewDay<=EntryBarStart,LowestOfDay ,1) * (1 - (EntryBufferPct/100)); 
//ORBHSL = ORBH * (1-(SLPct/100)); 
ORBHSL = ORBL; 
//ORBLSL = ORBL * (1+(SLPct/100));
ORBLSL = ORBH; 
ORBHTarget = ORBH * (1+(TargetPct/100));
ORBLTarget = ORBL * (1-(TargetPct/100));


//--Find Buy, Sell, Short & Cover Signals
BuySignal = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart); 
printf("\nBuySignal : " + BuySignal ); 
ShortSignal = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) ; 
printf("\nShortSignal  : " + ShortSignal ); 
BarsSinceLastBuySignal = (BarsSince(Ref(BuySignal,-1)) + 1);
BarsSinceLastShortSignal = (BarsSince(Ref(ShortSignal,-1)) + 1);
BarsSinceLastEntrySignal = Min(BarsSinceLastBuySignal, BarsSinceLastShortSignal);
BothEntrySignalsNull = IsNull(BarsSinceLastBuySignal) AND IsNull(BarsSinceLastShortSignal); //true for start of Day 1
printf("\n\nBarsSinceNewDay : " + BarsSinceNewDay ); 
printf("\n BarsSinceLastEntrySignal : " + BarsSinceLastEntrySignal); 
Buy = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < 

BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Sell = (L <= ORBHSL) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastBuySignal); 
Short = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < 

BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Cover = (H >= ORBLSL) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastShortSignal); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Handle if ORB broken both sides on same bar
//--And remove duplicate Sell & Cover signals, since ExRem did not work as needed when Buy & Sell on same bar
orbBothSides = IIf(Buy AND Short, 1, 0); 
Buy = IIf(orbBothSides AND C <= O, 0, Buy); 
Short = IIf(orbBothSides AND C > O, 0, Short); 
Sell = IIf(orbBothSides AND C > O AND (L <= ORBHSL), 1, Sell); 
Sell = IIf((BarsSince(Buy) < (BarsSince(Ref(Sell,-1))+1)) OR (BarsSince(Buy) AND IsNull(BarsSince(Ref(Sell,-1)))),Sell,0);
Cover = IIf(orbBothSides AND C <= O AND (H >= ORBLSL), 1, Cover); 
Cover = IIf((BarsSince(Short) < (BarsSince(Ref(Cover,-1))+1)) OR (BarsSince(Short) AND IsNull(BarsSince(Ref(Cover,-

1)))),Cover,0);
printf("\n\norbBothSides : " + orbBothSides); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Special Condition for 18 & 19 May 2009 for the Indian Market
Buy =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Buy );
Sell =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Sell );
Short =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Short );
Cover =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Cover );

//--Set prices
BuyPrice = IIf(Buy, ORBH, Null); 
SellPrice = IIf(Sell, IIf(H >= ORBHTarget, ORBHTarget, Max(ORBHSL, L)), Null); 
ShortPrice = IIf(Short, ORBL, Null); 
CoverPrice = IIf(Cover, IIf(L <= ORBLTarget, ORBLTarget, Min(ORBLSL, H)), Null); 

//--Plot ORB, and SL 
Plot(ORBHSL,"",colorRed,styleDashed); 
Plot(ORBLSL,"",colorRed,styleDashed); 
Plot(IIf(TargetPct == MaxTarget, Null, ORBHTarget),"",colorGreen,styleDashed);
Plot(IIf(TargetPct == MaxTarget, Null, ORBLTarget),"",colorGreen,styleDashed);
PlotOHLC( ORBL, ORBH, ORBL, ORBH, "", colorBlack, styleCloud); 
 
//--Plot Signals
shape1 = Buy * shapeUpArrow + Sell * shapeDownArrow; 
PlotShapes( shape1, IIf( Buy, colorGreen, colorGreen), 0, IIf( Buy, Low, High ) ); 
shape2 = Cover * shapeUpArrow + Short * shapeDownArrow; 
PlotShapes( shape2, IIf( Cover, colorRed, colorRed), 0, IIf( Cover, Low, High ) ); 
GraphXSpace = 5; 

//--Restore time frame 
TimeFrameRestore(); 
_SECTION_END();
 
Shruti

I think I have modified the code as you wanted.But I would suggest you limit yourself to a limited number of stock.


Code:
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() ); 
range = Param("ADX Periods", 10, 2, 200, 1 );
r1 = Param( "Macd Fast avg", 12, 2, 200, 1 );
r2 = Param( "Macd Slow avg", 26, 2, 200, 1 );
r3 = Param( "Macd Signal avg", 9, 2, 200, 1 ); 
myADX = ADX(range);
myMacd = MACD(r1,r2);
mySignal = Signal(r1,r2,r3);

//1. Buy when MACD gives bullish Signal AND ADX is above 20 and below 30 .
Buy = myMacd > mySignal AND myADX > 20 AND myADX<30;
//2. Sell when MACD gives negative Signal OR u get decent 25 points OR market is closed. 
Sell = myMacd < mySignal OR Cross(H, ValueWhen(Buy,Close)+25) OR TimeNum()>152500;
//3. Short when MACD gives bearish Signal AND is above 20 and below 30 
Short = myMacd < mySignal AND myADX > 20 AND myADX<50;
//4. Cover when MACD gives bullish Signal OR u get decent 25 points OR market is closed.
Cover = myMacd > mySignal  OR Cross(ValueWhen(Short,Close)-25,L) OR TimeNum()>152500; 

Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short, Cover);
Cover= ExRem(Cover,Short);
// exploration
Filter = Buy OR Short; 
AddColumn(Close, "Close", 1.2);
AddColumn(Buy, "Buy", 1.0);
AddColumn(Short, "Short",1.0);
_SECTION_END();
PlotShapes(Buy* shapeUpArrow,colorBlue, 0,L, Offset=-45); 
PlotShapes(Short* shapeDownArrow,colorRed, 0,H, Offset=-45);
PlotShapes(Sell*shapeHollowDownArrow,colorRed,0,L,-51);
PlotShapes(Cover*shapeHollowUpArrow,colorBlue,0,H,-51);
A link I got from this forum



Amit ji,

code is not matching my need...


Happy ji pls help
 

amitrandive

Well-Known Member
Amit ji,

code is not matching my need...


Happy ji pls help
Shruti

My mistake,typing error.
Please note that I have only modified the ADX conditions that you had specified

Code:
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() ); 
range = Param("ADX Periods", 10, 2, 200, 1 );
r1 = Param( "Macd Fast avg", 12, 2, 200, 1 );
r2 = Param( "Macd Slow avg", 26, 2, 200, 1 );
r3 = Param( "Macd Signal avg", 9, 2, 200, 1 ); 
myADX = ADX(range);
myMacd = MACD(r1,r2);
mySignal = Signal(r1,r2,r3);

//1. Buy when MACD gives bullish Signal AND ADX is above 20 and below 30 .
Buy = myMacd > mySignal AND myADX > 20 AND myADX<30;
//2. Sell when MACD gives negative Signal OR u get decent 25 points OR market is closed. 
Sell = myMacd < mySignal OR Cross(H, ValueWhen(Buy,Close)+25) OR TimeNum()>152500;
//3. Short when MACD gives bearish Signal AND is above 20 and below 30 
Short = myMacd < mySignal AND myADX > 20 AND myADX<30;
//4. Cover when MACD gives bullish Signal OR u get decent 25 points OR market is closed.
Cover = myMacd > mySignal  OR Cross(ValueWhen(Short,Close)-25,L) OR TimeNum()>152500; 

Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short, Cover);
Cover= ExRem(Cover,Short);
// exploration
Filter = Buy OR Short; 
AddColumn(Close, "Close", 1.2);
AddColumn(Buy, "Buy", 1.0);
AddColumn(Short, "Short",1.0);
_SECTION_END();
PlotShapes(Buy* shapeUpArrow,colorBlue, 0,L, Offset=-45); 
PlotShapes(Short* shapeDownArrow,colorRed, 0,H, Offset=-45);
PlotShapes(Sell*shapeHollowDownArrow,colorRed,0,L,-51);
PlotShapes(Cover*shapeHollowUpArrow,colorBlue,0,H,-51);
 
Last edited:

nac

Well-Known Member
I am thinking for more than an hour and searched, but couldn't figure out how to code this. Seemed simple at first, but...

This is just for exploration/scanning.
Price touches ema(20); It's not a price crossover. Just want this in scanning result whenever price (anywhere in the day's range) touches the moving average.

TOUCH20 = Price touches EMA(20);

Filter = 1;

Addcolumn (TOUCH20,"TOUCH20");
 
I am thinking for more than an hour and searched, but couldn't figure out how to code this. Seemed simple at first, but...

This is just for exploration/scanning.
Price touches ema(20); It's not a price crossover. Just want this in scanning result whenever price (anywhere in the day's range) touches the moving average.

TOUCH20 = Price touches EMA(20);

Filter = 1;

Addcolumn (TOUCH20,"TOUCH20");
Code:
TOUCH20 = H > EMA(C,20) AND L < EMA(C,20);
Filter = TOUCH20;
Addcolumn .... 
Addcolumn ....

Happy :)
 

amitrandive

Well-Known Member
I am thinking for more than an hour and searched, but couldn't figure out how to code this. Seemed simple at first, but...

This is just for exploration/scanning.
Price touches ema(20); It's not a price crossover. Just want this in scanning result whenever price (anywhere in the day's range) touches the moving average.

TOUCH20 = Price touches EMA(20);

Filter = 1;

Addcolumn (TOUCH20,"TOUCH20");
Just found something similar.But some expert needs to modify.

This scans for stocks that have either the top 1/8 of the bar or the bottom 1/8 touching a moving average (choosable) of the current time frame.


Code:
// ---------- Title Section -----------------------
// MA cutting Top 1/8th (12.5%) of Candle
// by MarketMonk
// 2011-08-05

// -------- Parameter Variables Section ----------
// Moving Average Period
MAP = Param("Period for Mov Avg " , 50, 10, 240, 1);

// --------- Initialization Section --------------
// Top 1/8th point on current candle
T8P = (((High - Low) * .775) + Low);
// calculate Mov Ave Point
MAV = MA(C,MAP);
// Green for +, Red for -, Blue for no change
CC = IIf(C>Ref(C,-1), colorGreen, IIf(C<Ref(C,-1), colorRed, colorBlue));

// --------- Filter Section ----------------------
// MA has to be less than or equal to candle high AND
// MA has to be greater than or equal to Top 1/8th Point on the candle
Filter = (MAV <= High) AND (MAV >= T8P);

// -------- Display Results Section -------------
// whatever you want here, can be simple to fancy
// I would suggest the following to help you troubleshoot
// this code, as well as understand each candle so as
// to be able to determine if this is indeed what you
// are looking for

// Today's Closing information
AddColumn(C, "Close", 2.2, CC, colorYellow, 50);
AddColumn(C-Ref(C,-1), "Net", 2.2, CC, colorYellow, 45);
AddColumn(ROC(C,1), "%Net" ,2.1, CC,colorYellow, 40);
// Program Variable Details used in Filter section
AddColumn(H, "High", 2.2, colorBlack, colorYellow, 50);
AddColumn(MAV, "MAP", 2.2, colorBlack, colorYellow, 50);
AddColumn(T8P, "T8P", 2.2, colorBlack, colorYellow, 50);
 
Guyss... Need a small modification on the below code. Its ORB strategy, after the initial 5 minutes, based on the breakout/breakdown it shows signal.

However, i would like to add the below condition.

1. we go long when opening range high is broke with opening range low as stop loss.

when stop loss hits, the system exits the position. But I want to reverse the trade, by exiting the long position and going short with opening range high as stop loss, when this trade's stop loss hit, we should exit the trade, no more trades.

2. we go short when opening range low is broke with opening range high as stop loss.

when stop loss hits, the system exits the position. But I want to reverse the trade, by exiting the short position and going long with opening range low as stop loss, when this trade's stop loss hit, we should exit the trade, no more trades.

code:
Code:
function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}




_SECTION_BEGIN("Augubhai's ORB System v1.1"); 

//--Intraday time frame 
TimeFrameSet(in5Minute); //If reseting, check formula for TimeFrameInMinutes 
TimeFrameInMinutes = 5;

//--Define all params 
EntryBufferPct = ParamOptimize("Entry Buffer %", 0, 0, 0, 0);
SLPct = ParamOptimize("SL %", 0, 0, 0, 0);
TargetPct = ParamOptimize("Target %", 0, 0, 0, 0);
MaxTarget = 100;
TargetPct = IIf(TargetPct == 0, MaxTarget, TargetPct); 
EntryTimeStart = ParamOptimize("Entry Time Start (Minutes)", 5, 5, 120, 5);
EntryBarStart = floor(EntryTimeStart/TimeFrameInMinutes) - 1;
EntryTimeEnd = ParamOptimize("Entry Time End (Minutes)", 425, 10, 180, 5);
EntryBarEnd = floor(EntryTimeEnd/TimeFrameInMinutes) - 1;
EntryBarEnd = IIf(EntryBarEnd < EntryBarStart, EntryBarStart, EntryBarEnd);  

//--Plot Price Candle Chart
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 | GetPriceStyle() ); 

//--New Day & Time. End Day & Time . End Day & Time is null till end of day 1  
NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0; 
printf("\n NewDay  : " + NewDay ); 
EndDay = (Day()!= Ref(Day(), 1)); 
printf("\n EndDay  : " + EndDay );
FirstBarTime = ValueWhen(NewDay,TimeNum(),1); 
EndTime = ValueWhen(EndDay,TimeNum(),1);
SquareOffTime = 152000;

//--Calculate ORB, and SL
HighestOfDay = HighestSince(NewDay,H,1); 
LowestOfDay = LowestSince(NewDay,L,1); 
BarsSinceNewDay = BarsSince(NewDay);
ORBH = ValueWhen(BarsSinceNewDay<=EntryBarStart,HighestOfDay ,1) * (1 + (EntryBufferPct/100)); 
ORBL = ValueWhen(BarsSinceNewDay<=EntryBarStart,LowestOfDay ,1) * (1 - (EntryBufferPct/100)); 
//ORBHSL = ORBH * (1-(SLPct/100)); 
ORBHSL = ORBL; 
//ORBLSL = ORBL * (1+(SLPct/100));
ORBLSL = ORBH; 
ORBHTarget = ORBH * (1+(TargetPct/100));
ORBLTarget = ORBL * (1-(TargetPct/100));


//--Find Buy, Sell, Short & Cover Signals
BuySignal = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart); 
printf("\nBuySignal : " + BuySignal ); 
ShortSignal = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) ; 
printf("\nShortSignal  : " + ShortSignal ); 
BarsSinceLastBuySignal = (BarsSince(Ref(BuySignal,-1)) + 1);
BarsSinceLastShortSignal = (BarsSince(Ref(ShortSignal,-1)) + 1);
BarsSinceLastEntrySignal = Min(BarsSinceLastBuySignal, BarsSinceLastShortSignal);
BothEntrySignalsNull = IsNull(BarsSinceLastBuySignal) AND IsNull(BarsSinceLastShortSignal); //true for start of Day 1
printf("\n\nBarsSinceNewDay : " + BarsSinceNewDay ); 
printf("\n BarsSinceLastEntrySignal : " + BarsSinceLastEntrySignal); 
Buy = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < 

BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Sell = (L <= ORBHSL) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastBuySignal); 
Short = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < 

BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Cover = (H >= ORBLSL) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastShortSignal); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Handle if ORB broken both sides on same bar
//--And remove duplicate Sell & Cover signals, since ExRem did not work as needed when Buy & Sell on same bar
orbBothSides = IIf(Buy AND Short, 1, 0); 
Buy = IIf(orbBothSides AND C <= O, 0, Buy); 
Short = IIf(orbBothSides AND C > O, 0, Short); 
Sell = IIf(orbBothSides AND C > O AND (L <= ORBHSL), 1, Sell); 
Sell = IIf((BarsSince(Buy) < (BarsSince(Ref(Sell,-1))+1)) OR (BarsSince(Buy) AND IsNull(BarsSince(Ref(Sell,-1)))),Sell,0);
Cover = IIf(orbBothSides AND C <= O AND (H >= ORBLSL), 1, Cover); 
Cover = IIf((BarsSince(Short) < (BarsSince(Ref(Cover,-1))+1)) OR (BarsSince(Short) AND IsNull(BarsSince(Ref(Cover,-

1)))),Cover,0);
printf("\n\norbBothSides : " + orbBothSides); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Special Condition for 18 & 19 May 2009 for the Indian Market
Buy =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Buy );
Sell =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Sell );
Short =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Short );
Cover =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Cover );

//--Set prices
BuyPrice = IIf(Buy, ORBH, Null); 
SellPrice = IIf(Sell, IIf(H >= ORBHTarget, ORBHTarget, Max(ORBHSL, L)), Null); 
ShortPrice = IIf(Short, ORBL, Null); 
CoverPrice = IIf(Cover, IIf(L <= ORBLTarget, ORBLTarget, Min(ORBLSL, H)), Null); 

//--Plot ORB, and SL 
Plot(ORBHSL,"",colorRed,styleDashed); 
Plot(ORBLSL,"",colorRed,styleDashed); 
Plot(IIf(TargetPct == MaxTarget, Null, ORBHTarget),"",colorGreen,styleDashed);
Plot(IIf(TargetPct == MaxTarget, Null, ORBLTarget),"",colorGreen,styleDashed);
PlotOHLC( ORBL, ORBH, ORBL, ORBH, "", colorBlack, styleCloud); 
 
//--Plot Signals
shape1 = Buy * shapeUpArrow + Sell * shapeDownArrow; 
PlotShapes( shape1, IIf( Buy, colorGreen, colorGreen), 0, IIf( Buy, Low, High ) ); 
shape2 = Cover * shapeUpArrow + Short * shapeDownArrow; 
PlotShapes( shape2, IIf( Cover, colorRed, colorRed), 0, IIf( Cover, Low, High ) ); 
GraphXSpace = 5; 

//--Restore time frame 
TimeFrameRestore(); 
_SECTION_END();
Happy, amit,

could you please help me out??
 

trash

Well-Known Member
I am thinking for more than an hour and searched, but couldn't figure out how to code this. Seemed simple at first, but...

This is just for exploration/scanning.
Price touches ema(20); It's not a price crossover. Just want this in scanning result whenever price (anywhere in the day's range) touches the moving average.

TOUCH20 = Price touches EMA(20);

Filter = 1;

Addcolumn (TOUCH20,"TOUCH20");
Here is alternative to add "near MA" occurrences

Code:
// by trash

MAequalval = 0.05;  // MA equality in percent, 0.01 means within 0.01% of MA
MAequalval = MAequalval * 100000;

MA_ = EMA( C, 20 );

// don't touch but be near MA
MAequalityL = Nz( AlmostEqual( L, MA_, MAequalval ) ) AND L > MA_;
MAequalityH = Nz( AlmostEqual( H, MA_, MAequalval ) ) AND H < MA_;

// touch MA
touch = H > MA_ AND L < MA_;

condition = touch OR MAequalityL OR MAequalityH;

Plot( MA_, "MA", colorGold, styleLine );
PlotShapes( condition*shapeSmallSquare, colorGold, 0, MA_, 0 );
EDIT: removed redundant code parts
 
Last edited:

Similar threads