Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

First independent community of traders

First independent community of traders Logo First independent community of traders Logo

First independent community of traders Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • Buy Theme
  • Home
  • About Us
  • Blog
  • Contact Us
Home/ Questions/Q 901
russian_hedge_fund
russian_hedge_fund

russian_hedge_fund

  • 1 Question
  • 1 Answer
  • 0 Best Answers
  • 22 Points
View Profile
  • 0
russian_hedge_fund
Asked: December 18, 20202020-12-18T09:55:02+00:00 2020-12-18T09:55:02+00:00

OCO Orders + Trailing Stop

  • 0

hi guys please help me solve the problem with the trailing stop i want to add it to oco orders

No matter how hard I try but the code doesn’t work I don’t know where the error is

when compiling, there are no errors, OCO Orders works, trailing stop does not work

Thank you very much in advance

#include
CTrade trade;

void OnTick()
  {

   double Balance=AccountInfoDouble(ACCOUNT_BALANCE);

   double Equity=AccountInfoDouble(ACCOUNT_EQUITY);

   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);

   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits);

   if(PositionsTotal()==0 && OrdersTotal()==0)
     {

      trade.BuyStop(1,Ask+3*_Point,_Symbol,Ask-27*_Point,Ask+63*_Point, ORDER_TIME_GTC,0,0);

      trade.SellStop(1,Bid-3*_Point,_Symbol,Bid+27*_Point,Bid-63*_Point, ORDER_TIME_GTC,0,0);

     }

   if(Balance!=Equity)
      {
      
      CancelOrder();
      
      }
    
   TrailingStop(Ask, Bid);  

}

void CancelOrder()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {

      ulong OrderTicket = OrderGetTicket(i);

      trade.OrderDelete(OrderTicket);

     }

  }

void TrailingStop(double Ask, double Bid)
{

   double SL_Ask = NormalizeDouble(Ask-7*_Point, _Digits);
  
   double SL_Bid = NormalizeDouble(Bid+7*_Point, _Digits);
  
   for (int i=PositionsTotal()-1; i>=0; i--)
   {
  
      string symbol=PositionGetSymbol(i);
      
      if (_Symbol==symbol)
      {
      
         ulong PositionTicket = PositionGetInteger(POSITION_TICKET);
        
         double CurrentSL = PositionGetDouble(POSITION_SL);
        
         if(CurrentSL>SL_Ask)
         {
        
         trade.PositionModify(PositionTicket,(CurrentSL+3*_Point),0);
        
        
         }
        
         if(CurrentSL3*_Point),0);
        
        
         }
        
      }
  
   }

}

  • 0 0 Answers
  • 0 Followers
  • 0
Answer
Share
  • Facebook
    Leave an answer

    Leave an answer
    Cancel reply

    Browse

    Sidebar

    Ask A Question

    Stats

    • Questions 504
    • Answers 2k
    • Posts 5
    • Comments 0
    • Best Answers 0
    • Users 681
    • Popular
    • Comments
    • Tags
    • forexcommunity

      Highlighting what’s important about questions & Answers on Discy Community!

      • 0 Comments
    • forexcommunity

      Introducing Keyboard Shortcuts, our first Labs feature

      • 0 Comments
    • forexcommunity

      Defining quality on Discy Engine — what a helpful answer ...

      • 0 Comments
    • forexcommunity

      Organizational and company accounts on Discy Engine the next step

      • 0 Comments
    • forexcommunity

      Hello world!

      • 0 Comments

    Users

    Leonardcig

    Leonardcig

    • 0 Questions
    • 0 Answers
    DennisByday

    DennisByday

    • 0 Questions
    • 0 Answers
    Haroldmeary

    Haroldmeary

    • 0 Questions
    • 0 Answers

    Footer

    First independent community of traders

    About

    An independent community of forex traders. This is where traders communicate. You can ask your questions and you will receive an answer to your question.
    • Terms of Use
    • Privacy Policy
    • Cookie Policy
    • Knowledge Base
    • Support

    © 2021 Forexcommunity.net. All Rights Reserved