BUY Until Close Condition Met


Category:
0
0

Hi Pete,

I have written a simple back testing program for my strategy and I am now stuck. The program works fine, except that if an additional buy condition occurs before my sell condition is triggered, it just ignores the additional sell condition (which I want included). For example, If my strategy says to buy when the price low touches the lower Bollinger Band, and to sell when it touches the upper band, I want it to include another buy if it touches down twice before touching the upper band. This is the code I have currently which isn’t working:

def BUY = Low <= lowerBand;
def SELL = high >= upperBand ;

AddOrder(OrderType.BUY_TO_OPEN, BUY, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = “BUY”);
AddOrder(OrderType.SELL_TO_CLOSE, SELL, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = “SELL”);

Any help you can provide would be much appreciated. Thanks, Ron

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on December 8, 2021 11:17 am
86 views
0
Private answer

Your question is a duplicate. But I will allow this question to be posted since you were not able to find the solution when searching this forum. The term for what you are trying to accomplish is called "scaling in", but sometimes it may also be referred to as "pyramiding".

Here is the original post that answers your question:

https://www.hahn-tech.com/ans/how-to-scale-orders/

The solution has nothing to do with the code. This is a setting.

And the code you provided was incomplete, in that it does not provide a fully functioning section of code that other viewers may copy/paste into their own custom chart strategy. I have updated your code to include the missing pieces so other visitors to this post have a fully functioning section of code:

def BUY = Low <= BollingerBands().LowerBand;
def SELL = high >= BollingerBands().UpperBand ;
AddOrder(OrderType.BUY_TO_OPEN, BUY, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, SELL, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "SELL");

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on December 8, 2021 2:15 pm