Money Management

Hello everybody,

Hope you are doing well during the pandemic.
Suppose that I have $100,000 in my account with a leverage of 100. In each trade, I want to risk 1% of my capital ($1000). Suppose I have a trading system that provides me with buy and sell signals (like the crossover of MAs) and the open price of the next candle is the buy or sell price. Now, I want to have a stop-loss 20 pips lower than the entry candle. In other words, the difference between the open price and 20 pips lower than the low of the candle worths $1000 (1% of my capital). Therefore, if the price goes lower than the 20 pips, I would incur $1000 otherwise I would be in profit. Take profit would be the other signal (buy or sell).
Could you please help how I can code it?
Thanks in advance for your help :smiling_face_with_three_hearts:

You can use ApplyStop functions.

For your stop loss, you would use 0 = stopTypeLoss. maximum loss stop

1 Like

It is mandatory advice to read/search AB knowledge base first. Majority of basic questions are answered there already.

http://www.amibroker.com/kb/2014/10/12/position-sizing-based-on-risk/

1 Like

Thanks for your reply.

You have enabled Reverse Signal forces exit setting. Can't you see it? So disable it.

Btw, here is what I think about a table without header and code insersion without code tags:

Thank you so much for your reply.
I think you didn't understand what I meant. I want to have a small stop-loss but when I change "TradeRisk" to less than 1%, I don't find any results in the backtest report. Why is that? Please help me. Thanks in advance for your help.

TradeRisk = 1; // trade risk in percent equals to max. loss percentage stop

These are the titles:
image

That one was your question to which I responded.
You do not have implemented any profit target stop in code (whether you have set one in UI settings is unknown).

So you have to add profit target stop in addition to stop loss if you want to exit at fix profit. If you only want to exit at stops then set Sell and Cover to zero.

Also you have to set to Futures mode if trading via margin account but not adding e.g. 200% to SetPositionSize.


http://www.amibroker.com/kb/2006/08/09/amibroker-for-forex/

Additional 3rd party tutorial on FX
https://drive.google.com/file/d/0B3jlgZS4w7DyOWJEaXN4bDhEQzA/view

1 Like

First of all, thank you so much for your reply and for sharing the documents and links with me.
Secondly, thanks for your patience because I am not professional in coding like you.

I think I didn't explain clearly what I am looking for and you misunderstood. I am not looking for any target, just want to fix my stop-loss.
If I write the following code, I have long and short trades and each trade will stop as soon as a new signal (buy or sell) appears.
short = sell;
cover = buy;

If I write a code as you said, I have only long trades and they will stop as soon as the sell signals appear.
Sell = 0;
Cover = 0;

This is the report of the backtest:

image

So far, I am ok and thank you.
Here you can find the setting of my backtest:

image
image
image

The problem is that I want to risk 1% of my capital (100,000) which means $1000 in each trade but if you take a look at the report you find that the 1% profit is $9.43. Actually it should be $1000 or in other words, I expect to see $1000.

image

It means that the difference between my entry price and stop-loss doesn't worth $1000 (1%) and it confuses me :frowning:
image

image

Could you please help me with it? Thanks in advance for your help and your patience.
I belive if I can draw the stop-loss, it can help me a lot to understand the problem. Do you know how I can draw the stop-loss on the chart?

Best regards,

To clarify more, please take a look at the below pic, I want to define a stop-loss which is 20 pips lower than the low of the buy signal and risk 1% of the capital which would be $1000. So, if the price goes down and hit the stop-loss, I will lose $1000; however, for this signal price moved up (almost two times of my risk) and I expect to find about $2000 as profit.

image

How can I define a stop-loss as 20 pips lower than the low of the buy signal or 20 pips higher than the low of the sell signal?
How can I say the difference between the stop-loss (as defined above) and entry point should worth 1% of my capital?