Distinguishing between long and short trades, and long and short exits

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #10398 quote
    merc1203
    Participant
    Average

    Is it possible to distinguish between the following 4 types of changes in position?

    Long entry

    Long exit (on stop)

    Short entry

    Short exit (on stp)

    In an algo that checks for both long entry’s and short entry’s, I want only to enter a new long at a HIGHER price than the previous long entry, and a new short at a LOWER price than the previous short entry.

    This may or may not be higher/lower than the previous TRADE as the last trade could be an exit on stop which in effect I want to ignore

    Thanks

    #10400 quote
    Nicolas
    Keymaster
    Master

    You can retrieve the open price of each previous trade with TRADEPRICE instruction. This way you can decide to take position higher or lower than this price.

    #10403 quote
    merc1203
    Participant
    Average

    Yes – but the question is, how do I distinguish between the different types of trades, as described above. I guess from your answer this is not possible?

    What happens if the sequence of trades is 1) sell, 2) sell, 3) buy and 4) sell stopped out. I then want to sell more. How do I isolate the last sell price – tradeprice(3)? – and distinguish it from tradeprice(2) – the buy – and tradeprice(1) – the sell stopped out?

    #10405 quote
    mr.brymas
    Participant
    Average

    Not really sure what you mean but you don´t write “sell” when you want to short. You write it like this:

    //buy long

    If blabla then

    buy 1 contract at market

    //sell long

    If blabla then

    sell at market

     

    /enter short

    If blabla then

    sellshort 1 contract at market

     

    //exit short

    If blabla then

    exitshort at market

    #10409 quote
    Nicolas
    Keymaster
    Master

    Try to give a variable a value when you launch a buy or a sell order, like this:

    if conditionlong then 
     buy 1 share at market 
     a = 1 //trade is a buy order
    endif
    
    if conditionshort then 
     sellshort 1 share at market 
     a = -1 //trade is a sell order
    endif

    Then if you want to know what were the direction of the previous 3rd trade, you can access to the variable “a” with a little barindex play:

    longORshort = a[barindex-tradeindex(3)]

    So if “longORshort” return -1, then you know that your previous 3rd trade from now was a sell order.

    I have not tested it, but it should work .. I think 🙂

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

Distinguishing between long and short trades, and long and short exits


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
merc1203 @merc1203 Participant
Summary

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

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