NexusFi: Find Your Edge


Home Menu

 





Waiting for some bars before entry


Discussion in Platforms and Indicators

Updated
    1. trending_up 1,903 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 1 attachments




 
Search this Thread

Waiting for some bars before entry

  #1 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3

I want to create a code for scaling in if the same conditions are met 3 times.

i.e., if there is a buy signal and again BUY signal conditions are met before SELL (LongExit) condition, then the system could take the BUY signals upto 3 times and then exit all at the SELL condition.
i have a code which works like this but it generates 3 signals on 3 continuous candles which leads to losses. have attached image for clarity.

now i need to create a code which waits for a certain number of candles before scaling in.

somebody please help!

Attached Thumbnails
Click image for larger version

Name:	1.JPG
Views:	202
Size:	17.1 KB
ID:	242389  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
ZombieSqueeze
Platforms and Indicators
Cheap historycal L1 data for stocks
Stocks and ETFs
How to apply profiles
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #2 (permalink)
alligator
paris france
 
Posts: 10 since Sep 2013
Thanks Given: 8
Thanks Received: 5

I am not sure to understand you correctly. I guess you want to scale-in every time you get a Buy signal, up to 3 times. And sell your whole position when you get a Sell signal. But you also want to wait for n bars after last Buy signal before buying more. In that case,
let's say your long signals are given by a BuySignal variable and your sell signals by a SellSignal.

 
Code
n = Param("Delay to scale in", 5, 1, 20);
maxScaleIn = Param("Max scale in", 3, 1, 10);

Delay = BarsSince(BuySignal); // Bars since last Buy signal
Pos = Flip(BuySignal, SellSignal); // position in the market

BuyFirst = (Pos > 0) AND (Ref(Pos, -1) <= 0); // first buy signal, no delay
BuyMore = BuySignal AND (Delay >= n); // next signals, n bars delay
BuyNoMore = (Sum(BuyMore, BarsSince(BuyFirst)) + 1) >= maxScaleIn;
Buy = BuyFirst OR BuyMore AND (NOT BuyNoMore);

Similarly for the short side. I haven't check code but it should be ok. Have fun.

Reply With Quote
Thanked by:
  #3 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3



alligator View Post
I am not sure to understand you correctly. I guess you want to scale-in every time you get a Buy signal, up to 3 times. And sell your whole position when you get a Sell signal. But you also want to wait for n bars after last Buy signal before buying more. In that case,
let's say your long signals are given by a BuySignal variable and your sell signals by a SellSignal.

 
Code
n = Param("Delay to scale in", 5, 1, 20);
maxScaleIn = Param("Max scale in", 3, 1, 10);

Delay = BarsSince(BuySignal); // Bars since last Buy signal
Pos = Flip(BuySignal, SellSignal); // position in the market

BuyFirst = (Pos > 0) AND (Ref(Pos, -1) <= 0); // first buy signal, no delay
BuyMore = BuySignal AND (Delay >= n); // next signals, n bars delay
BuyNoMore = (Sum(BuyMore, BarsSince(BuyFirst)) + 1) >= maxScaleIn;
Buy = BuyFirst OR BuyMore AND (NOT BuyNoMore);

Similarly for the short side. I haven't check code but it should be ok. Have fun.

Alligator,

thanks a lot for your reply. the code is not working though. it is generating only one buy signal instead of three. i will see what can be done now. thanks again.

Reply With Quote
  #4 (permalink)
alligator
paris france
 
Posts: 10 since Sep 2013
Thanks Given: 8
Thanks Received: 5

I don't have time to check, but there's at least on error preventing more than 1 buy. Replace Delay by:

 
Code
Delay = Ref(BarsSince(BuySignal), -1) + 1;

Reply With Quote
Thanked by:
  #5 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3

Alligator,

its working. Thanks a lot.

Reply With Quote




Last Updated on October 13, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts