I've managed to finally put together my first test script and am running it in demo, but I need some clarification on some things that don't make sense.
The script is just a test script to practice coding, so please don't worry about profitability and such. I've written it the way I have in order to build to something bigger later, so that's why it's only looping one algo, but is set up to add algos later on.
The algo is just the one in Workshop 4, with optimization as in Workshop 5 and looping assets as in Workshop 6 with some small changes:
function tradeTrend() { TimeFrame = 1; vars Price = series(price()); vars Trend = series(LowPass(Price,optimize(1000,500,1500))); vars Signals = series(0);
{ if(strstr(Algo,"TRND1A") and strstr(Asset,"AUD/USD")) tradeTrend(); else if(strstr(Algo,"TRND1A") and strstr(Asset,"CHF/USD")) tradeTrend(); }
PlotWidth = 600; PlotHeight1 = 300; }
So here are my questions, which I hope someone can help me with:
1) As you can see, the algo uses stops and take profit: SL 10*ATR, TP 20*ATR. Should these stops and limits appear on the broker's platform, or do they function internally within Zorro?
2) In line with the above, the algo opened two trades as follows:
[AUD/USD:TRND1A:L8153] Long 1@0.9113 Risk 345. [USD/CHF:TRND1A:L8194] Long 1@0.9093 Risk 391.
a) the algo is trading 0.01 lots – I assume the risk is in pips not $?
b) in the case of of AUDUSD, 10*ATR at the time of opening the trade was 345 pips, so this is correct, but 10*ATR at the time of opening USDCHF was 220 pips, so this obviously doesn't match Zorro's risk – what is going on here?
c) should take profit appear in the Zorro window as well as risk? i.e. how do I know Zorro is getting the TP right, esp. since it apparently didn't get the SL right in the case of CHF?
d) In the case of both trades, stops did appear on my broker platform when the trades opened, but the stops are completely unrealistic and don't align in any way with ATR:
- in the case of AUDUSD the stop is 0.39362, compared with open price of 0.9113, i.e. 5,177 pips away (15x the risk in the Zorro window)
- in the case of USDCHF the stop is 0.37616, compared with open price of 0.9093, i.e. 5,332 pips away (13.6 times the risk in the Zorro window and 24x what the risk should be)
What is going on with this? Also, no TP appeared on the broker platform. In case it matters, I haven't set up any risk or margin sliders or such.
3) On another note, how do I change the algo to trade 0.1 lots instead of 0.01?
I hope someone can help me with this. Many thanks in advance!!
How stops and limits work is explained in much better detail in the manual than I could explain here. Look here: http://manual.zorro-trader.com/stop.htm. The profit, risk, loss etc. in the messages are money, not pips. Setting different trade sizes is dealt with in workshop 6. You can use the "Lots" or "Margin" variables.
Your manual has a search function that leads you directly to the page that you need. Once you've read it and do not understand something, just ask here.
Re: Need help with script
[Re: jcl]
#433277 11/27/1313:5211/27/1313:52
OK, I've been scouring the manual again and again, but it unfortunately it doesn't answer most of my questions:
1) If the risk in the Zorro window is in account currency units, that means Risk 345 = $345 in the case of a $ account. With a trade size of 0.01 lots (i.e. $0.10 / pip), that would mean Risk 345 = SL 3,450 pips. The ATR at the time was 34.5 pips, so 10*ATR = 345 pips = $34.50. So the risk should be Risk 34.5, not Risk 345. Why would it be off by a factor of 10?
I checked the log file from the test and in the log file the risk was mostly accurately displayed. That is to say, if ATR at the time of the trade was 37 pips, the risk was listed as, e.g. Risk 41. I can understand a difference of a few pips, but not a factor of 10.
2) In the case of the USDCHF trade, ATR at the time of opening the trade was 22 pips, so 10*ATR = 220 pips = $22, which means the risk should be Risk 22. But the Zorro window says Risk 391. This is a factor of 19.5. Why would it be so far off?
I again checked the log file, and in this case I did notice greater discrepancies between the listed risk and the ATR at the time of a trade. For example, in one case ATR was 37 pips, but the risk was Risk 51, a difference of 14 pips. Still, it's not a factor of 10 or 20.
3) OK, I found the part of the manual explaining that SL and TP are handled internally by Zorro and not displayed to the broker. But what then are the huge 5K pip stops that appear on the broker platform?
I ran the tests using the data downloaded from the Zorro site. I checked the ATR against FXCM's charts using the ATR indicator.
I've been looking all through the manual, and I can't find anything that addresses the above issues, so I hope you can help me with this.
You could be simulating the wrong type of broker account, which could explain why your figures are off by a factor of 10.
If you expect $0.10/pip then I believe that it a micro account. Therefore, you should use a line like this to make sure you are simulating that type of account:
The risk displayed in the message is the real risk - this money will be really gone from your account if your trade hits the SL. If it is by factor 10 higher than you expect, you're trading ten times more risky than you intended.
What dusktrader said is correct: First you need to know what account you have. From your post, I suspect you wanted a micro lot account, but have opened a mini lot account instead. This explains the factor 10. You're also not trading 0.1 or 0.01 lot as you think, but 1 lot. 1 lot is the default and the minimum order size for your account. The 22/391 discrepancy might be some other calculation mistake, like forgetting the pip cost. You can find all formulae in the manual:
Quote:
The risk of a trade - the maximum possible loss at a given Stop distance - is Lots * (Stop/PIP) * PIPCost. The number of lots equivalent to a given margin is (Margin/MarginCost).
If you do not know what account you have, you can find a short script under "Tips&Tricks" that prints the lot size of your account. Do not continue trading until you are sure that you got the right account and the displayed risk is exactly the value that you expect. You can easily test trade parameters by running a little script on a demo account that opens trades with a fixed SL and TP. You can then see how your account changes after every trade.
Re: Need help with script
[Re: jcl]
#433311 11/27/1317:4511/27/1317:45
Thank you for the links and help, but this still doesn't resolve the issue.
I simulated the strategy on a micro account and the broker account is also a micro account. And the strategy correctly opened micro lots. So this does not explain the factor of 10.
As for the factor of 19.5, I'm not sure what calculation mistake there can be in 10*ATR unless Zorro is calculating ATR incorrectly. It would be very helpful if the log file would show where the strategy has placed the SL and TP, that way I could verify whether it's placing the stop correctly and by deduction, if it's calculating ATR correctly. Is there anyway to do that?
The code to the strategy is above. As I said, it's basically the code from Workshops 4 & 5, so if there are any miscalculations in the code, they should appear there. If not, then Zorro is getting something wrong.
This is what I know to be true:
Zorro shows Risk 345 Zorro opens 0.01 lots with the broker The pip value of 0.01 lots is $0.10
This means either:
a) all the above is true and the stop is 3,450 pips away, which means Zorro is miscalculating ATR by a factor of 10;
b) Zorro is correctly calculating ATR and placing the stop, but is miscalculating the risk; or
c) Zorro is calculating ATR and risk correctly, but thinks it's trading mini lots while in fact opening micro lots with the broker.
I tried adding "AssetList = "AssetsMicro.dta" to the code to test it, but got a syntax error, so I'm not sure how to ensure that Zorro knows it's trading micro lots, not minis.
Also, this doesn't explain the 22/391 discrepancy, which can only be explained by miscalculating ATR. It also doesn't explain the 5K pip SL placed with the broker.
Would it matter in any way that it's a 5-digit broker?
No, it does not matter if it is a 5 digits broker. Unless the broker has set up wrong parameters to his MT4 server. This is theoretically possible, but I have not yet heard of such a case.
If Zorro or the Workshop 4 script would calculate something "wrong", I would expect that this happened with all Zorros and not only just with yours. So this is not a very likely scenario either.
I think for making progress we should stop guessing and agree first about what account you have. If you can't run a test script, please post the Assets.dta file content - it also contains your basic account parameters. Afterwards I'll show you how to run a script that prints the SL distance and calculates the risk.
Re: Need help with script
[Re: jcl]
#433324 11/28/1307:1011/28/1307:10
This is indeed a micro account, as you can see from the lot size of 1000 contracts. In the next step we'll deal with how to calculate the risk of a trade. Afterwards we can check if your MT4 version behaves as it should.
You now need to run a test script. You can use the "TradeTest" script that you should have in your folder. Please modify it so that the parameters you had problems with, especially the risk, are now manually calculated and printed:
Run this script by clicking "Test", and then check the log file. Compare the risk that you've calculated in the script with the risk displayed by Zorro. Let me know if you do not understand something in the script.
After you did that, the next step would be trading this script live and checking if your MT4 version does everthing correctly.
Re: Need help with script
[Re: jcl]
#433347 11/28/1312:1611/28/1312:16
Here the manually calculated risk does not match the displayed risk.
Then I traded the first script. Attached is a screenshot showing Zorro and MT4 (TestScript1). Here you can see that the manually calculated risk - 12.00 - and displayed risk - 12 -match and that MT4 opened the trade with the correct risk - 12 pips + spread.
Then I traded the second script with the ATR stop and profit. As with the test, the attached screenshot (TestScript2_10*ATR) again shows a mismatch between the manually calculated risk - 2.0 - and the displayed risk - 138 - and MT4 has the stop 2,718 pips away.
I then traded this script with Stop = 1*ATR(20) and TakeProfit = 1*ATR(20). The attached screenshot (TestScript2_1*ATR) shows a similar mismatch as with 10*ATR above, and MT4 again placed the stop 2,700 pips away.
Finally I traded the 1*ATR script on a FXCM mini account (as opposed to micro account). The attached screenshot (TestScript2_1*ATR_FXCM) agains shows the same discrepancy between the manually calculated risk - 17.0 - and the displayed risk - 1,375 (although in this case both are a factor of 10 greater because of trading a full standard lot). FXCM trade station didn't indicate any stop loss.
As one final test, I traded the same script on a FXCM MT4 micro account. The attached screenshot (TestScript2_1*ATR_FXCM_MT4) shows the same discrepancy, but the platform doesn't show a stop.