condition on add order

fat_tony

New member
I'm working on backtesting and I am having some trouble. I want to add a bubble on the chart that shows my entry and exits but only when the trade is first enterd. The issue I am having is I want to set up a flag so they when an order is added it will set the flag = 1. Is there any way to do this?

basically
def flag = if add order == yes then 1 else 0
 

pine

New member
@fat_tony Yes, you can use AddChartBubble() with the same conditional logic used in AddOrder()... Just place the AddChartBubble() call directly below your AddOrder()...
Sorry for hijacking this thread. I have a similar question on AddChartBubble and AddOrder.

I have BUY_AUTO and SELL_AUTO orders in my strategy. I also have SELL_TO_CLOSE and BUY_TO_CLOSE stop loss orders. Bubbles are used to display all the possible stop losses. The issue I'm having is that if the strategy is in a good BUY position, that is current price > Entryprice, my short order stop loss bubble is showing up, which makes sense because a short stop loss order logic is when current price > Entryprice. I would prefer only long order stop loss bubble to show up, if applicable. Is there a way to check if the strategy is currently in a BUY or SELL position, that way if it's in a BUY position, only long stop loss bubbles will show up, if SELL position, only short stop loss bubles will show up? Thanks!
 

rad14733

Well-known member
VIP
@pine You could setup a "state" logic variable structure that sets the state to 1 for Long entries, -1 for Short entries, or 0 when no trade is active and have it update after every iteration of the Strategy... Then you would monitor the states previous or current value, similar to state[1] or state, to identify the current state before taking any AddOrder() actions... It would essentially become another conditional criteria for AddOrder()... That's what popped into my head upon reading your post...
 

pine

New member
@pine You could setup a "state" logic variable structure that sets the state to 1 for Long entries, -1 for Short entries, or 0 when no trade is active and have it update after every iteration of the Strategy... Then you would monitor the states previous or current value, similar to state[1] or state, to identify the current state before taking any AddOrder() actions... It would essentially become another conditional criteria for AddOrder()... That's what popped into my head upon reading your post...
Currently I have

AUTO_BUY
AUTO_SELL

then

SELL_TO_CLOSE
BUY_TO_CLOSE

I assume that once either AUTO_BUY and AUTO_SELL order is hit, you're in position, and if the SELL_TO_CLOSE or BUY_TO_CLOSE condition is met, they will show up.

Sorry for my ignorance, could you guide me on how to set this "state" logic up?
 

rad14733

Well-known member
VIP
@pine You are correct... I'm sure you've also reviewed the StopLoss Strategies that come with TOS as well for ideas... If not, give them a review... Good luck...

There should be more than a few "state" logic examples coded into scripts here in the forums... I can't point you to one right now but if you can't find one I might have time later...
 

Similar threads

Top