ICHIMOKU STRATEGY - page 3

 

Ok it works in the strategy test now, however, more than one trade is placed - several every minute. Which bit of code should be changed?

And I understand that you guys must be pretty annoyed by now, but if you don't ask you don't get.

//+------------------------------------------------------------------+
//|                                              ICHIMOKU_SIMPLE.mq4 |
//|                      Copyright © 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double Lots = 1.0; 
//----
int start()
   {
   double tenkan_sen=iIchimoku(NULL, 0, 9, 26, 52, MODE_TENKANSEN, 1);
   double kijun_sen=iIchimoku(NULL, 0, 9, 26, 52, MODE_KIJUNSEN, 1);
   int ticket;
//----

// check for long position (BUY) possibility
      if(tenkan_sen>kijun_sen)
         {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+Point,"ichimoku",16384,0,Green);
         if(ticket>0)
            {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
            }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
         
         }   //  added by RaptorUK
            
   // SELL 
     {
      OrderSelect(SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL && // check for opened position 
         OrderSymbol()==Symbol()) // check for symbol
         {
         if(OrderType()==OP_BUY) // long position is opened
            {
            // should it be closed?
            if(tenkan_sen<kijun_sen)   //  removed surplus (  RaptorUK
               {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
               return(0); // exit
               }
            }
         }
      }
  return(0);
   }
 
ToBa:

Ok it works in the strategy test now, however, more than one trade is placed - several every minute. Which bit of code should be changed?

And I understand that you guys must be pretty annoyed by now, but if you don't ask you don't get.

Annoyed ? nope, not me . . . just trying to help you learn and you seem to be doing that . . . now you need to keep learning.
 

Okey dokey, I know it's to do with this line.

But I don't know what the numbers mean. I've tried to delete some parts, but I get ')' - wrong parameters count C:\Program Files (x86)\MetaTrader 4\experts\ICHIMOKU_F1.mq4 (21, 51)

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+Point,"ichimoku",16384,0,Green);
 
Read the documentation . . . click this --> OrderSend
 
ToBa:

Ok it works in the strategy test now, however, more than one trade is placed - several every minute.

First you need to figure out what you want it to do instead of placing several orders every minute . . . .
 

Ok I've made significant progress. However t/p is executed as soon as the pair price increases by 0.0001.

The code now looks like this:

//+------------------------------------------------------------------+
//|                                              ICHIMOKU_SIMPLE.mq4 |
//|                      Copyright © 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double Lots = 1.0;
//----

int start()
   {
   double tenkan_sen=iIchimoku(NULL, 0, 9, 26, 52, MODE_TENKANSEN, 1);
   double kijun_sen=iIchimoku(NULL, 0, 9, 26, 52, MODE_KIJUNSEN, 1);
   int ticket,total,order_id;
   
// BUY
      total=OrdersTotal();
   if(total<1 && tenkan_sen>kijun_sen)
         {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+Point,"ichimoku",16384,0,Green);
         } 
                      
// SELL 
   if(tenkan_sen<kijun_sen)   
         {
         OrderClose(order_id,1,Ask,3,Red);
         return(0);
         }     
  return(0);
   }
 
a t/p seems to be placed automatically; I don't know which part to change
 
ToBa:
a t/p seems to be placed automatically; I don't know which part to change
It's part of the OrderSend . . .
 
Ok I now know it's this bit - Ask+*Point but rather than putting a number, I want the t/p to be when tenkan-sen<kijun-sen
 
Set it to 0 then you will need to keep checking for when tenkan-sen<kijun-sen and then when it is you close the order . . . . the downside of this is that if you have an open order and you lose connection to the Internet your trade will stay open and a winning trade can turn into losing trade.
Reason: