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
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
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
I was writing while Nicolas posted his reply.
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
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.
Thanks @Nicolas
I have set these;
// Stops and targets
SET STOP PLOSS 4
SET STOP %TRAILING 1.5
SET TARGET %PROFIT 85
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
Yes, if you replace line 6 with
Exitshort at market
SELL is used to exit BUY and EXITSHORT to exit SELLSHORT.
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?
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.