Hello, I have problems with a complicated loop.
I think it would help me if someone could tell me whether the following is possible:
If I want to define a certain value like low [1] as selltrigger.
Is it possible to output this value as a concrete number,
in order to calculate with this number later in the process?
For example the low [1] was 89,10 EUR I want to code the Stop-Loss condition as:
if close<89,10 then
Sell size SHARES AT MARKET
I don´t want to code:
if close<low [1] then
Sell size SHARES AT MARKET!
Thanks for help 🙂
You can store any value in a variable and use it later in your code:
//firstly store the value in a variable whenever you want
if conditionToStore then
myValue = Low[1]
endif
//then use this variable to trigger your 'stoploss' (exit condition here)
if close < myValue then
Sell size SHARES AT MARKET
endif
Hello Nicolas, thanks for your answer! Sounds great.
Unfortunately, it does not work for me. When I run the code, I always get the error: “conditiontostore is not defined”(in german: Die folgende Variable ist nicht definiert:conditionToStore”…
Any idea?
Hello again,
now I see that what I wrote above was nonsens. I missinterpreted “conditionToStore” as a comand….
Here is my lousy code (I know it is not good and can´t work this way…). But since I am a beginner, maybay someone could help me with my approach.
_________________________
Hammeryes=0
Hammerup=0
Hammer = CALL Hammer
if Hammer[1] = 1 then
Hammeryes=1 and uptrigger=high[1] and downtrigger=low[1]
endif
//I want to check for the four following bars after the occurance of the Hammer if ONE of them could close obove the Hammer-High. If so, for exampel the 2nd one closed above, I want to break the check-up procedure.
for i = 0 to 3 do
if (close[i] < uptrigger) then
Hammerup=Hammerup
endif
else
if (close[i] > uptrigger) then
Hammerup=Hammerup+1
endif
break
if Hammerup=1 then
BUY 1 SHARES AT MARKET
endif
if longonmarket and close < downtrigger then
Sell 1 SHARES AT MARKET
endif
> For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<
If you want to trade the breakout of 2 defined levels, I suggest to use pending STOP orders instead. These pending orders will be set for the four following bars after an Hammer has been identified by the indicator you are “calling”:
Hammer = CALL Hammer
if Hammer[1] = 1 then
uptrigger=high[1] and downtrigger=low[1]
hammerbar = barindex[1]
endif
//check if the hammerbar is defined and if the hammer occurred in the last 4 bars
if hammerbar>0 and barindex-hammerbar<=4 then
buy 1 contract at uptrigger STOP
sellshort 1 contract at downtrigger STOP
endif
Please test the code and make comments.
Thank you Niklas that helps me very very much!
Without you I would never have come to this solution!
Best wishes
Michael
I made a typo while copy/paste your code in my last post, the correct code should be:
Hammer = CALL Hammer
if Hammer[1] = 1 then
uptrigger=high[1]
downtrigger=low[1]
hammerbar = barindex[1]
endif
//check if the hammerbar is defined and if the hammer occurred in the last 4 bars
if hammerbar>0 and barindex-hammerbar<=4 then
buy 1 contract at uptrigger STOP
sellshort 1 contract at downtrigger STOP
endif
Sorry for inconvenience 😐