Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
- Usually people who can't code don't receive free help on this forum.
- If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
- To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Documentation.
- If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
- Finally, you also have the option to hire a programmer in the Freelance section.
Fernando Carreiro #:
- Usually people who can't code don't receive free help on this forum.
- If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
- To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Documentation.
- If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
- Finally, you also have the option to hire a programmer in the Freelance section.
Fernando, thank you very much for your support. It's the first time I publish-post anything on forums; I would have done so correctly knowing the details you share with me.
Indeed I am clearly learning. No coding background whatsoever.
I will continue my research with the info you have provided. Again; thank you.
#include <Trade/Trade.mqh> CTrade trade; #define KEY_9 105 #define KEY_8 104 #define KEY_7 103 #define KEy_6 102 #define KEY_5 101 #define KEY_4 100 #define KEY_3 99 #define KEY_2 98 #define KEY_1 97 int OnInit() { return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_KEYDOWN){ if(lparam==KEY_9){ Print("9 was pressed"); trade.Buy(0.1); } if(lparam==KEY_8){ Print("8 was pressed"); trade.Buy(0.05); } if(lparam==KEY_7){ Print("7 was pressed"); trade.Buy(0.02); } if(lparam==KEy_6){ Print("6 was pressed"); trade.Sell(0.1); } if(lparam==KEY_5){ Print("5 was pressed"); trade.Sell(0.05); } if(lparam==KEY_4){ Print("4 was pressed"); trade.Sell(0.02); } if(lparam==KEY_3){ Print("3 was pressed"); for(int i = PositionsTotal()-1; 1>=0; i--){ ulong posTicket = PositionGetTicket(i); if(PositionSelectByTicket(posTicket)){ if(PositionGetString(POSITION_SYMBOL) !=_Symbol) continue; if(trade.PositionClose(posTicket)){ Print("> Pos #",posTicket,"was closed"); } } } } if(lparam==KEY_2){ Print("2 was pressed"); } } }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am developing an EA to trade with a small keyboard, coding its respective keys to give them specific trading functions.
I already coded SUCCESSFULLY the BUY, SELL, and CLOSE ALL hotkey scripts.,
However, I can't find the right parameters/coding functions for setting up the STOP LOSS key on a position.
Please help?
-
I would like for my KEY_2 to have the function of setting a stop loss to an existing, opened position (POSITION _SYMBOL), equivalent to -2.0% of my account balance whenever I press the KEY_2 ,
And I know there should be an "If" statement somewhere that determines if the Position is a BUY or SELL ; therefore, placing correctly the stop loss correctly.
Thank you very much to whoever guides me with this part of my HotKey Trading EA.