Thread: How to code?
View Single Post
  #24 (permalink)  
Old 02-23-2006, 11:06 AM
divergence_trader divergence_trader is offline
Junior Member
 
Join Date: Feb 2006
Posts: 9
divergence_trader is on a distinguished road
Code to move stoploss?

Hi all,

Coding an EA at the moment to autotrade for me, it's getting towards completion but i can't figure out how to move the stoploss on an open trade. i am posting my code here, if anyone could point out what i'm doing wrong i would greatly appreciate


This is the part of code which opens a LONG position:

PHP Code:

{
         if(
//long entry criteria met)
            
{
            if (
priorbartime == Time[0])
            return(
0);
            
priorbartime Time[0];
            
Alert("Long Signal");
            
ObjectCreate(arrowlongOBJ_ARROW0Time[0], Open[0], 0000);
            
ObjectSet(arrowlongOBJPROP_ARROWCODE233);
            
ObjectSet(arrowlongOBJPROP_COLORAqua);
            
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-StopLoss*Point,Ask+TakeProfit*Point,"am crossing",16677,0,Green);  // HDB CHANGED Close TO Ask and SlipPage to 0
         
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);
            }
    } 
then once the trade is open I want to manage it by moving stop to -5 when the trade is +15, and by moving stop to b/e when trade is +20. this is the code i have come up with so far but it doesnt seem to be working:

PHP Code:
total=OrdersTotal();
   if(
total>0)
      { 
      for(
cnt=0;cnt<total;cnt++)
         {
         
OrderSelect(cntSELECT_BY_POSMODE_TRADES);
         if(
OrderType()==OP_BUY && OrderSymbol()==Symbol())
            {
            if(
Bid-OrderOpenPrice()==Point*15)
               {
               
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*5,OrderTakeProfit(),0,Blue);
               return(
0);
               }
            if(
Bid-OrderOpenPrice()==Point*20)
               {
               
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue);
               return(
0);
               }
            }
         }
      } 
As mentioned, this is all for LONG positions.

Thanks for any help!

divergence_trader
Reply With Quote