- Joined
- 30 June 2007
- Posts
- 7,200
- Reactions
- 1,226
Thanks very much for the help, GB.
The NBar stop part is not working correctly. I am getting exits marked as 'n-bar' in the correct places, but the actual exit, the exit price, is the previous low, the same as the stop-loss exits. I'm trying to get the second exit to occur at the close of the third day.
Thanks very much for the help, GB.
The NBar stop part is not working correctly. I am getting exits marked as 'n-bar' in the correct places, but the actual exit, the exit price, is the previous low, the same as the stop-loss exits. I'm trying to get the second exit to occur at the close of the third day.
SetTradeDelays(1,0,1,1);
Buy = Cross(MACD(), Signal()); // Buy cross of MACD & signal line
Sell = L < Ref(L, -1); // Sell if current low is less than last bar low
SellPrice = Close; // Sell price for stop loss and sell condition is close price same bar as trigger (no delay in set trade delays)
BuyPrice = Open; // Buy price is open price 1 bar delay
ApplyStop(stopTypeNBar, stopModeBars, 3); // Exit position on bar 3 close (same bar with no delay set in trade delays)
Simple way.
Code:SetTradeDelays(1,0,1,1); Buy = Cross(MACD(), Signal()); // Buy cross of MACD & signal line Sell = L < Ref(L, -1); // Sell if current low is less than last bar low SellPrice = Close; // Sell price for stop loss and sell condition is close price same bar as trigger (no delay in set trade delays) BuyPrice = Open; // Buy price is open price 1 bar delay ApplyStop(stopTypeNBar, stopModeBars, 3); // Exit position on bar 3 close (same bar with no delay set in trade delays)
Applystop exit is determined by the sellprice that you stated.I thought the logic seemed correct but, for the NDay stop, I still get an exit price of yesterday's low, instead of the exit price being the close.
Exit immediately and then later you state exit yesterdays low price. Is that correct? If so, not possible as the exit bar may range may be below yesterdays bar. Best way is to deal with the quotes available.The first exit is a stop loss. I want to exit immediately if the low of the day crosses the low of the previous day
Applystop exit is determined by the sellprice that you stated. I think you will have to "loop" for different SellPrices.
Thanks. If you look at the sell price criteria the exit price of last bar low is not always possible because the exit bar may range less than previous bar as in piccy. You can't sell at the previous low because any price on exit bar does not meet it.Thanks for the help, Wysiwyg. I can't figure out how to apply a loop in this situation.
Thank for your earlier suggestion too. The NDay exits work fine, exiting at the close, as required. But, once you have set the SellPrice to Close, all the subsequent exits which are triggered by crossing yesterday's low also have the close of the bar as their exit price.
Thanks. If you look at the sell price criteria the exit price of last bar low is not always possible because the exit bar may range less than previous bar as in piccy. You can't sell at the previous low because any price on exit bar does not meet it.
View attachment 66483
You mean you want to sell for L<=Ref(L,-1) only if it happens the day after buying?... otherwise nbar=3?
If so:
Buy = ROC(C,1)>5; // change to your buy rules
Sellprice = Iif(ref(Buy,-1),Ref(L,-1),C); // if you bought yesterday, then sell if L<=Ref(L,-1), otherwise..
Sell = Sellprice>=L and Sellprice<=H;//
Applystop(stoptypenbar,stopmodebars,3);
Period = 14;
// Determines trend direction using DMI indicators
MDIFilter = MDI(period) > PDI(period);
// calculate the % change from the prior close in days
PCY = ((C-Ref(C,-10))/Ref(C,-10))*100;
PCY2 = ((C-Ref(C,-20))/Ref(C,-20))*100;
PCY3 = ((C-Ref(C,-40))/Ref(C,-40))*100;
PCY4 = ((C-Ref(C,-60))/Ref(C,-60))*100;
PCY5 = ((C-Ref(C,-80))/Ref(C,-80))*100;
PCY6 = ((C-Ref(C,-100))/Ref(C,-100))*100;
PCY7 = ((C-Ref(C,-120))/Ref(C,-120))*100;
PCY8 = ((C-Ref(C,-140))/Ref(C,-140))*100;
PCY9 = ((C-Ref(C,-160))/Ref(C,-160))*100;
PCY10 = ((C-Ref(C,-180))/Ref(C,-180))*100;
// Columns
NumColumns = 2;
Column0 = FullName();
Column0Name = "Ticker name";
Column1 = IIf(MDIFilter AND ((PCY OR PCY2 OR PCY3 OR PCY4 OR PCY5 OR PCY6 OR PCY7 OR PCY8 OR PCY9 OR PCY10) >= -40), 1, 0);
Column1Name = "Reversal Signal";
AddTextColumn( SectorID(1), "Sector" );
AddTextColumn( MarketID(1), "Market" );
// Look for stocks down a minimum of >= 40%
Filter = ADX(period) >= 30 AND Column1;
Buy = ADX(period) >= 30 AND Column1;
Also, is there a way to code the % of drop of x stock from y highs? My objective is to find stocks that have fallen 40% or more from the recent high but since i dont know how to code the "recent high" part i used from x amount of period.
Thanks
YearHigh2 = C - HHV(H, 250);
YearHigh1 = YearHigh2 / HHV(H, 250);
YearHighToPresent = YearHigh1 * 100;
Filter = YearHighToPresent;
AddTextColumn(WriteVal(YearHighToPresent), "Percent Fall", 1.2, colorBlue);
YearHigh2 = C - HHV(H, 250);
YearHigh1 = YearHigh2 / HHV(H, 250);
YearHighToPresent = YearHigh1 * 100;
Fallof40 = YearHighToPresent < -39;
Filter = Fallof40;
AddTextColumn(WriteVal(IIf(Fallof40, YearHighToPresent, 0)), "Percent Fall", 1.2, colorBlue);
((PCY OR PCY2 OR PCY3 OR PCY4 OR PCY5 OR PCY6 OR PCY7 OR PCY8 OR PCY9 OR PCY10) >= -40)
@Wysiwyg, i noticed my original included all the stocks from your code but also included stocks that did not fall >=40%. If you have the time, can you tell me what went wrong in the original code as such it still include stocks that did not fall more than 40%?
I imagine it has to do with this line?Code:((PCY OR PCY2 OR PCY3 OR PCY4 OR PCY5 OR PCY6 OR PCY7 OR PCY8 OR PCY9 OR PCY10) >= -40)
I replaced the original with yours, just trying to get a better understanding. Cheers.
Hi all.
I was wondering if anybody can let me know how to reference a previous signal from the past? eg higher than last swing high.
Thanks
swinghigh=Your code used to define a swing high;
H>ValueWhen(swinghigh,H,1);
Hi rnr. Many thanks for your help with this.
I was wondering if you could also tell me how to reference the last occurrence of this because at the moment my signal is generating breaks of all swing highs in the past?
The script also misses many breakouts of swing highs in my scan (I show the swing highs by plotshapes).
I've not idea why.
Any help would be greatly appreciated.
Swinghigh = H>Ref(H,-1) AND H>Ref(H,1);
breakout = (H>ValueWhen(swinghigh,H,1));
PlotShapes(shapeSmallCircle*swinghigh,colorgreen, 0, L, -40);
Buy = breakout;
swinghi= Peak(H,5,1);
Buy = Cross(C,Ref(swinghi,-1));
Plot(Zig(H,5),"",colorBlack);
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?