Trying to work out how to code a sell market order

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #90671 quote
    bartjawien
    Participant
    New

    hey guys,

    check this out;

    If (barindex+tradeindex) > barindex then //Long
    Sell at market
    endif

    I’m trying to ascertain how to sell when a position is open to go long however and the market  goes the opposite direction after say 10pips.

    So the code above if I understand it correctly is; if the total bars + position bars are less then the total bars this means the market is dipping and I’m forcing a sell at market.

     

    Is this correct or I am going mad?

     

    Thanks in advance.

    Bart

    #90676 quote
    Nicolas
    Keymaster
    Master

    barindex+tradeindex will always be more than barindex, so with this condition you are always trying to close the buy order.

    If you want to stop (exit) a buy order if the market has declined of 10 pips since its open, just use a stop loss:

    set stop ploss 10
    #90684 quote
    robertogozzi
    Moderator
    Master

    Your code will exit immediately because that condition will always be true!

    BarIndex is, say, 2000 and a trade is opened. Tradeindex will be assigned 2000 by ProOrder. Next bar their sum will yield 4001 which is > BarIndex.

    To count the number of bars since a trade opened you must subtract TradeIndex from BarIndex.

    I don’t understand what bars elapsed have to do with profits.

    If you want to sell when price is -10 pips then you have to compare TradePrice against current Close, of course you can also combine the two to exit after 5 bars have elapsed and profit is -10:

    If (BarIndex - TradeIndex) > 5 AND (Close - TradePrice) < -10 * PipSize Then
       Sell at market
    Endif
    Bel thanked this post
    #90685 quote
    robertogozzi
    Moderator
    Master

    I was writing while Nicolas posted his reply.

    #90688 quote
    bartjawien
    Participant
    New

    Thanks @Nicolas

    Heres what am trying to achieve;

    On Long, if buy price is less then -4pips then sell

    On short, if buy price is more then +4pips then sell

     

    I guess what am trying to do is sell should the market run up/down in the correct direction and then reverse on itself.

    Here is scenario #1: I buy long at 1.556 and the market goes up by 10pip and the order is sold at 95% sells which is perfect and a win

    Here is scenario #2:I buy long at 1.556 and the market goes up by 3pip at and suddenly crashes, I would like to sell as soon as -0.002pip ????

     

    Thanks gents, appreciate the replies

    #90690 quote
    Nicolas
    Keymaster
    Master

    On Long, if buy price is less then -4pips then sell On short, if buy price is more then +4pips then sell

    If you mean “exit order” by “then sell”, the solution I wrote in the above post is still good. Put a stoploss at 4 pips.

    #90692 quote
    bartjawien
    Participant
    New

    Thanks @Nicolas

    I have set these;

    // Stops and targets
    SET STOP PLOSS 4
    SET STOP %TRAILING 1.5
    SET TARGET %PROFIT 85

    #90708 quote
    bartjawien
    Participant
    New

    Thanks @robertogozzi

    #90728 quote
    bartjawien
    Participant
    New

    Hey guys,

    Will this work

    If longonmarket and (BarIndex - TradeIndex) >= 5 AND (Close - TradePrice) < -4 * PipSize Then
    Sell at market
    endif
    
    If shortonmarket and (BarIndex - TradeIndex) >= 5 AND (Close - TradePrice) > 4 * PipSize Then
    Sell at market
    Endif
    #90729 quote
    robertogozzi
    Moderator
    Master

    Yes, if you replace line 6 with

    Exitshort at market

    SELL is used to exit BUY and EXITSHORT to exit SELLSHORT.

    #90782 quote
    bartjawien
    Participant
    New

    Thanks @robertogozzi

    Is there a way to alert or shown me each time a condition runs?

    In the C++ days I would be able to trigger Print. (Sorry am a little new to the prorealtime language.) I understand you can use Return for indicator but what is the call for autotrading?

    #90797 quote
    robertogozzi
    Moderator
    Master

    PRT supports a subset of the BASIC language, with just one data type (numeric, double I guess) and no arrays. FUNCTIONS are implemented with indicators which can be CALLed with a line like:

    var1,var2,var3,.... = CALL "My Indicator"[Param1, Param2,...]

    to the left of the “=” symbol you need to place the variables whose values are RETURNed by the indicator, while within brackets you supply the indicator with the data it needs to work with.

    Strategies cannot set/trigger alerts, only indicators can return data that you can use on a chart to set alerts.

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

Trying to work out how to code a sell market order


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
bartjawien @bartjawien Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/07/2019
Status: Active
Attachments: No files
Logo Logo
Loading...