Hi
how would you code wanting a break of the previous bar low On the bar prior to the highest bar since the code was activated ? And if a new highest bar was achieved it then moves to recognise the new bar as the highest so targets the bar previous low ?
A picture / screen shot tells a thousand words?
I’ve read it 4 times and it still isn’t forming a picture in my mind … I might be tired!? 🙂
This is what I coded, provided I could correctly understand what you meant:
IF BarIndex = 0 THEN
// initialization of variables
MyHI = high
MyBAR = 0
Entry = 0
ELSE
// find new HIGH (MyHI), if any, and eventually update bar index (MyBAR)
MyHI = max(MyHI,high)
MyBAR = max(MyBAR,BarIndex * (MyHI <> MyHI[1]))
ENDIF
IF BarIndex > 3 THEN
//we need at least 3 bars:
// 1 = the HIGHest
// 2 = the bar prior to the HIGHEST
// 3 = the LOW of the bar PRIOR to #2
i = BarIndex - MyBAR
Entry = low[i - 2]
ENDIF
// ENTRY is the price you want to break
Try adding this indicator to your chart, to display a histogram whenever a new HIGH is found (start with 200 units, to make sure you don’t have to scroll backwards too far):
IF BarIndex = 0 THEN
// initialization of variables
MyHI = high
MyBAR = 0
//Entry = 0
ELSE
// find new HIGH (MyHI), if any, and eventually update bar index (MyBAR)
MyHI = max(MyHI,high)
MyBAR = max(MyBAR,BarIndex * (MyHI <> MyHI[1]))
ENDIF
IF BarIndex > 3 THEN
//we need at least 3 bars:
// 1 = the HIGHest
// 2 = the bar prior to the HIGHEST
// 3 = the LOW of the bar PRIOR to #2
//i = BarIndex - MyBAR
//Entry = low[i - 2]
ENDIF
x = 0
IF MyHI <> MyHI[1] THEN
x = 1
ENDIF
RETURN x AS "Signal"
Thanks GRAHAL, good idea I’ve now uploaded screen shots – first shows initial set up it takes the highest new bar SINCE code activated. and would trigger a sell when the low of the previous bar is hit . If a new higher bar is achieved it ignores the previous and resets with this new bar and takes the previous bar low as the trigger.
Roberto
Is it also possible that if the previous bar close is NOT lower than the current bar close nothing is triggered and it looks back to find a previous bar close that is lower than the current bar to activate on ?
There you go:
IF close[1] >= close THEN
// add here the code preventing an event from being triggered
ENDIF
Roberto
The code just enters on the first bar close from when the code is activated, every time – seems to be no relation to your code just added a c1 and c2 ?
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
IF BarIndex = 0 THEN
// initialization of variables
MyHI = high
MyBAR = 0
Entry = 0
ELSE
// find new HIGH (MyHI), if any, and eventually update bar index (MyBAR)
MyHI = max(MyHI,high)
MyBAR = max(MyBAR,BarIndex * (MyHI <> MyHI[1]))
ENDIF
IF BarIndex > 3 THEN
//we need at least 3 bars:
// 1 = the HIGHest
// 2 = the bar prior to the HIGHEST
// 3 = the LOW of the bar PRIOR to #2
i = BarIndex - MyBAR
Entry = low[i - 2]
c1= myhi>6535
c2=entry-2
ENDIF
if not daysforbiddenentry and c1 and c2 then
SELLSHORT 3 perpoint AT MARKET
// ENTRY is the price you want to break
// Stops and targets
SET STOP pLOSS 100
SET TARGET pPROFIT 100
endif
?? am i doing something wrong ?