Meta trader 5

 

Hey, Can I get some quick help here. I'm starting to hate metatrader 5. I really don't understand it at all and every tutorial that I've tried to learn from is wrong in some form or another.

Here's an example of what I'm talking about. Here's a code that I found that I copied and here are my errors.

'trade' - '{' beginning bracket expected tst.mq5 3 14
'{' - function definition unexpected tst.mq5 7 1
'}' - expressions are not allowed on a global scope tst.mq5 62 2
3 errors, 0 warnings 4 1
#include<Trade\Trade.mqh>

class Ctrade trade;


void OnTick();
{

   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK),_Digits);
   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID),_Digits);
   
   
   if (PositionsTotal()==0)
   {
   trade.Buy(0.10,NULL,(Ask-100*_Point),(Ask+100*_Point), (Ask+100), NULL);
   
   string MyLastPositionType=GetLastClosedPositionType();
   void Comment("last position was", "\n" string MyLastPositionType);
   }


string GetLastClosedPositionType()
{
 uint TotalNumberofDeals = HistoryDealsTotal();
 ulong TicketNumber = 0;
 long OrderType, DealEntry;
 string MySymbol="";
 string PositionDirection="";
 
 HistorySelect(0, TimeCurrent());
 
 for(uint i=0;i<TotalNumberofDeals;i++)
 {
 if((TicketNumber=HistoryDealGetTicket(i))>0)
 {
 OrderType = HistoryDealGetInteger(TicketNumber, DEAL_TYPE);
 
 MySymbol=HistoryDealGetString(TicketNumber, DEAL_SYMBOL);
 
 DealEntry=HistoryDealGetInteger(TicketNumber,DEAL_ENTRY);
 
 if(MySymbol==_Symbol)
 {
 if(DealEntry==DEAL_ENTRY_OUT)
 {
 if(OrderType==ORDER_TYPE_SELL)
 {
 PositionDirection="BUY-TRADE";
 }
 
 }
 }
 
 
 
 }
 
 
 
 }
 return PositionDirection;
 
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
 
Tim G.: Hey, Can I get some quick help here. I'm starting to hate metatrader 5. I really don't understand it at all and every tutorial that I've tried to learn from is wrong in some form or another. Here's an example of what I'm talking about. Here's a code that I found that I copied and here are my errors.

Your "found" code is totally badly written (probably generated by ChatGPT or some other A.I.). In other words, it's useless.

Here is that standard default response ...

  • Please, don't request help for ChatGPT (or other A.I.) generated code. It generates horrible code.
  • 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 Book and Documentation
  • Remember also, that you can debug your code with MetaEditor's own debugging functionality.
  • 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.
Reason: