Hello
I am a mother of 2 with no very much time to sit in front of the computer to watch all day the charts for set ups and I am trying to get into setting up a simple automated system. Can someone show me where I have gone wrong? Most appreciate your kind assistance.
I would also be thankful for some pointers where I can read up / watch the best learning material for programming PRT.
if average[8]<close[1] then
if open>close[1] then
signal=low
stoploss=lowest[5](low)
takeprofit=(close-stoploss)*2
else
signal=0
endif
endif
return signal,stoploss
this code is for an indicator
Thanks for the pointer.
I have rewritten the set up and there is an issue with the stop as it doesn’t properly trails the position.
Furthermore the system doesn’t open every time the conditions are met a new position
Do you know if there are any sample codes so that I can see what the approximate set up would need to look like?
Post the code you have written doing Copy and Paste, please.
Good morning.
here the code, my main issues are that the code doesn’t open on each bar a position although the conditions are fulfilled and the stop is just a simple trailing stop and I would like to have it move from low close [1] to the next candle. But not sure how to write this code.
Truly appreciate you taking time to help me out, means the world to me. Thank you!
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
DEFPARAM FLATBEFORE = 083000
DEFPARAM FLATAFTER = 220000
// Conditions to enter long positions
indicator1 = ExponentialAverage[20](close)
c1 = (close >= indicator1[1])
IF c1 THEN
BUY 0.5 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
indicator2 = ExponentialAverage[20](close)
c2 = (close CROSSES UNDER indicator2[1])
IF c2 THEN
SELL AT MARKET
ENDIF
SET STOP TRAILING 10
// Conditions to enter short positions
indicator1 = ExponentialAverage[20](close)
c1 = (close <= indicator1[1])
IF c1 THEN
SELLSHORT 0.5 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
indicator2 = ExponentialAverage[20](close)
c2 = (close > indicator2)
Hope this is ok.
I have moved this topic to ProOrder support, as it deals with strategies. Please use the correct support forum and read carefully the basic rules below (highlighted in yellow). Thank you 🙂
Your code is missing the last lines to exit Short trades:
IF c2 THEN
EXITSHORT AT MARKET
ENDIF
as to the trailing stop, it will be updated every 10 pips (oor 10 price units, if not an index).
Hi Roberto
thank you for reviewing my code, I am stuck again and was wondering if you would be so kind to help me out. When I backtest this code it doesn’t give me any trades and I don’t see the trees for the forest anymore.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
EMA20 = ExponentialAverage[20](close)
EMA50 = ExponentialAverage[50](close)
avg169 = Average[169](close)
c1 = EMA20 CROSSES OVER EMA50
c2 = close [0] > close [1]
IF c1 AND c2 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
c3 = close [0] < avg169
IF c3 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
EMA20 = ExponentialAverage[20](close)
EMA50 = ExponentialAverage[50](close)
avg169 = Average [169]
c4 = EMA20 CROSSES UNDER EMA50
c5 = close [0] < close [1]
IF c4 AND c5 THEN
SELL 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
c6 = close > avg169
IF c6 THEN
SELL AT MARKET
ENDIF
You have to change the instruction to enter and exit a SHORT trade:
- BUY enters a Long trade
- SELL exits a Long trade
- SELLSHORT enters a Short trade
- EXITSHORT exits a Short trade
JSParticipant
Senior
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
EMA20 = ExponentialAverage[20](close)
EMA50 = ExponentialAverage[50](close)
avg169 = Average[169](close)
c1 = EMA20 CROSSES OVER EMA50
c2 = close[0] > close[1]
IF c1 AND c2 THEN
Buy 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
c3 = close[0] < avg169
IF c3 THEN
Sell AT MARKET
ENDIF
// Conditions to enter short positions
EMA20 = ExponentialAverage[20](close)
EMA50 = ExponentialAverage[50](close)
avg169 = Average [169]
c4 = EMA20 CROSSES UNDER EMA50
c5 = close[0] < close[1]
IF c4 AND c5 THEN
SellShort 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
c6 = close > avg169
IF c6 THEN
ExitShort AT MARKET
ENDIF
Thanks you are a champ.
Please let me know if my ‘stupid’ questions annoy you. But this is a lot of fun trying to get my ideas into a script.
Appreciate your help! Absolutely fantastic.
Ciao
I love GraHal‘s motto “Ask a question, you may be a fool for a day. Don’t ask a question, you may be a fool for life“.
Thank you Roberto.
I just changed it slightly as we never view anyone as a fool for asking questions.
Ask a question, you may feel like a fool for a day.
Don’t ask a question, you may be a fool for life!?
Roberto
Here we go again!
I am trying to get the code to open the candle right after the crossing, which it doesn’t do right now, see picture below. I tried to specify the candle which should trigger the entry, however now the system it returns an error message.
// Conditions to enter long positions
EMA20 = ExponentialAverage [20]
EMA50 = ExponentialAverage [50]
IF EMA20 CROSSES OVER EMA50 THEN
LongCrossingPrice = close
IF open [0] > close [1] THEN
BUY 0.5 CONTRACT AT MARKET
ENDIF
IF close [0] < EMA50 THEN
SELL 0.5 CONTRACT AT MARKET
ENDIF
// Conditions to enter short positions
EMA20 = ExponentialAverage [20]
EMA50 = ExponentialAverage [50]
IF EMA20 CROSSES UNDER EMA50 THEN
ShortCrossingPrice = close
IF open < close [1] THEN
SELLSHORT 0.5 CONTRACT AT MARKET
ENDIF
IF close [0] > EMA50 THEN
EXITSHORT 0.5 CONTRACT AT MARKET
ENDIF
where have I gone wrong? Appreciate you pointing me in the right direction. 😉
Re above … no picture attached (as you said).
Does below answer your question?
Code is read at the end of each bar and entries / exits etc occurs at the begginning of the next bar (after code is read).
Next bar open – and thus entry / exit – is only a few milliseconds after previous bar close.
I believe all trading platform work same as above.
Not really because I don’t see where my mistake in the code is.
I thought I followed the structure of codes, thanks for pointing out the error