Get current price and entry price

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #177941 quote
    2point1
    Participant
    New

    Hi,

    Can anyone please advise who in the code part it is possible to get the market price as I can only see the open, close, high and low price options, but not the market price. Also is it possible to see the entry price? My aim is to do something like this:

    If LongOnMarket AND close[1] < (ENTRYPRICE- 15) AND MARKETPRICE < (ENTRYPRICE - 10) THEN
    SELL AT MARKET
    ENDIF

    Thanks

    #177945 quote
    Swingueur
    Participant
    Average

    Hello,

    I believe strategies are made on close only. To get a market price in between, best would be to lower the timeframe as small as possible (1min etc…)
    Regarding entryprice, you have the instruction POSITIONPRICE

    Fabrice

    #177954 quote
    GraHal
    Participant
    Master

    Close is the market price at any stage during candle formation.

    Close is also the market price at candle close.

    #177955 quote
    robertogozzi
    Moderator
    Master

    What Swingueur  said is correct.

    As to the entry price, TRADEPRICE, or TRADEPRICE(1) (they are equivalent), is the correct answer. It is ALWAYS tha last price traded.

    After entry, TRADEPRICE will retain the entry price, after exit TRADEPRICE will retain the exit price and the entry price will then be retained by TRADEPRICE(2).

    After any operation it is shifted by one place.

    Swingueur thanked this post
    #177972 quote
    2point1
    Participant
    New

    Hi GraHal,

    When I use Close, the system only takes into account the close value of the bar. In real life automated trading, I would like the system to monitor the current price, e.g. If I enter a trade in DAX and the price moves by 15 points, I would move my Stop Loss to +2 points, so that in the event of  price turning against me, and not reaching my target of e.g. 30 points, I would not go into loosing trade, but would exit with only 2 points gain. Where as in the backtesting I am unable to tell the system to behave in this manner. This is the code I came up with, but as you can see in the screenshot it is not doing as I am telling it to do.

    emaShort = 9
    emaLong = 21
    ema200 = 200
    
    avgShort = ExponentialAverage[emaShort](Close)
    avgLong = ExponentialAverage[emaLong](Close)
    avg200 = ExponentialAverage[ema200](Close)
    
    IF NOT LongOnMarket AND NOT ShortOnMarket THEN
    IF avgShort CROSSES OVER avgLong AND Open > avg200 THEN
    BUY 1 CONTRACTS AT close+2 STOP
    ENDIF
    IF avgShort CROSSES UNDER avgLong AND Open < avg200 THEN
    SELLSHORT 1 CONTRACTS AT close-2 STOP
    moveSL=0
    ENDIF
    ENDIF
    
    SET STOP pLOSS 20
    SET TARGET pPROFIT 30
    
    IF ShortOnMarket THEN
    myAlert = PositionPrice-10
    myBE = PositionPrice-3
    IF close < myAlert THEN
    moveSL=1
    ENDIF
    IF moveSL AND close > myBE THEN
    EXITSHORT AT MARKET
    ENDIF
    ENDIF

    The blue line is the entry
    Green line is alert level, i.e. when the price has already moved by 10 points
    Red line, is where the buyback should occur, i.e. if the price has gone to 10 points my way, and then it reaches the 3 point below my entry then sell.

    example.png example.png
    #177974 quote
    robertogozzi
    Moderator
    Master

    Use MTF support.

    Searching the forum for MTF will return blogs, posts and plenty of code to learn how to use it.

    #177984 quote
    2point1
    Participant
    New

    Hi robertogozzi,

    Do you know what is the smallest time frame possible?

    I tried running the following code in 1 tick timeframe but the system would not even enter a trade:

     

    IF close crosses under 15047 THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF
    #177988 quote
    robertogozzi
    Moderator
    Master

    1 second is the smallest one.

    Non-time based TFs, like ticks, cannot be used for automated trading.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

Get current price and entry price


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
2point1 @2point1 Participant
Summary

This topic contains 7 replies,
has 4 voices, and was last updated by robertogozzi
4 years, 4 months ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 09/20/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...