Tradeprice query

Viewing 2 posts - 1 through 2 (of 2 total)
  • #252332

    I want to code an application building up a short position (sellshort) to say CountOfPosition = 5.

    Position 1 opened at start of application the subsequent trades opened following an increment above Tradeprice.

    So far so good.

    If the market falls the short positions are scaled out of incrementally (Exitshort).

    New short positions are entered if the market rises again again an increment above Tradeprice.

    My query.

    If there has been an ExitShort (and this is the last most recent action) is TradePrice readjusted to this level (of the Exitshort) or does it stay at the level of the
    previous Sellshort.

    A broader question is how possible is it to “watch” variables as the code is executing to see how the variables are changing.

    Thank you.

    #252554

    Following up on your questions about POSITIONPRICE and how to monitor variables, sometimes the best way to understand the concepts is with a complete, practical code example.
    The code below is a full trading system for a LONG position that scales into the trade on pullbacks. Although it’s a long strategy, you can apply the exact same principles in reverse to build the SHORT system you described.
    How the Code Works:
    1)Initial Entry: The system enters a buy order only on the bar where the ema20 crosses over the ema100.
    2)Static Levels: At the moment of entry, it calculates all future entry and exit levels based on the ATR (E1-E4, TP1-TP4, stoploss). These levels remain fixed for the entire duration of the trade.
    3)Scaling-In: If the price pulls back to the predefined entry levels (E1, E2, etc.), the system adds more contracts to the position.
    4)State Management: A variable n is used to count how many contracts have been added, ensuring the scaling-in happens in an orderly manner.

    Key Takeaways for Your Questions
    This example directly demonstrates the solutions to your original queries:
    1)How to “Watch” Variables: The code uses graphonprice to draw all the calculated price levels and graph n to plot the number of open contracts. This is the most effective way to visualize your system’s internal logic and debug it.
    2)POSITIONPRICE Behavior: We’ve specifically included the line graphonprice positionprice …. When you apply this to a chart, you will see a fuchsia line representing the average position price. Notice that this line only moves when a new buy order is executed.

Viewing 2 posts - 1 through 2 (of 2 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login