Arrow Code Function

 

I would like a function I can add to my EA (any of them) that I can use to test indicator language.

For example, if I have an indicator that triggers, (MACD cross over) I would like to call the Arrow Function and

have the arrow printed on the chart on that bar.

I'm really new at Forex (couple months) and even newer at programing, so simplicity is best. So far I just can't figure out how to do this.

Is there a function already out there I can copy and put in my EA?

Thanks for your patience.

 

you can use/modify mine

each arrow needs to have an exculsive number so make a static int counter and at each signal do cnt++

then use that as the first parameter, dir parameter is the arrow direction, type parameter is just to make a different color arrow for different types of signal, price is obviously just the bid or the ask or your MA value to position the star on the chart at the right place.

so if you have a buy signal, you call it like this make_arrow(cnt,0,0,ask);

That should make an upwards pointing arrow below the price bars and a star at the ask price, both the same color.

void make_arrow(int cnt, int dir, int type, double price)
  {string S2[6]={" buy"," sell"," buyclose"," sellclose"," other"," other"};
  
   ObjectCreate("Trade "+cnt+S2[type],OBJ_ARROW,0,Time[0],0); 
   ObjectCreate("Trade "+cnt+S2[type]+" ",OBJ_ARROW,0,Time[0],price);
   
   switch(dir)
//---- arrow directions: 0=up 1=down 3=sideways
    {case 0:  ObjectSet("Trade "+cnt+S2[type],OBJPROP_ARROWCODE,241);
              ObjectSet("Trade "+cnt+S2[type],OBJPROP_PRICE1,price-avbars()-(type*Point));
              ObjectSet("Trade "+cnt+S2[type]+" ",OBJPROP_ARROWCODE,172); break;
     case 1:  ObjectSet("Trade "+cnt+S2[type],OBJPROP_ARROWCODE,242);
              ObjectSet("Trade "+cnt+S2[type],OBJPROP_PRICE1,price+avbars()+(type*Point));
              ObjectSet("Trade "+cnt+S2[type]+" ",OBJPROP_ARROWCODE,172); break;
     case 3:  ObjectSet("Trade "+cnt+S2[type],OBJPROP_ARROWCODE,243);
              ObjectSet("Trade "+cnt+S2[type],OBJPROP_PRICE1,price-avbars()-(type*Point));
              ObjectSet("Trade "+cnt+S2[type]+" ",OBJPROP_ARROWCODE,172); break;
     default: Alert("error: make_arrow() Unknown Direction");
    }
   switch(type)
//---- types: 0=buy 1=sell 2=buyclose 3=sellclose 4=other 5=other
    {case 0:  ObjectSet("Trade "+cnt+S2[type],OBJPROP_COLOR,Lime);
              ObjectSet("Trade "+cnt+S2[type]+" ",OBJPROP_COLOR,Lime); break;
     case 1:  ObjectSet("Trade "+cnt+S2[type],OBJPROP_COLOR,Red);
              ObjectSet("Trade "+cnt+S2[type]+" ",OBJPROP_COLOR,Red); break;
     case 2:  ObjectSet("Trade "+cnt+S2[type],OBJPROP_COLOR,Yellow);
              ObjectSet("Trade "+cnt+S2[type]+" ",OBJPROP_COLOR,Yellow); break;
     case 3:  ObjectSet("Trade "+cnt+S2[type],OBJPROP_COLOR,Orange);
              ObjectSet("Trade "+cnt+S2[type]+" ",OBJPROP_COLOR,Orange); break;
     case 4:  ObjectSet("Trade "+cnt+S2[type],OBJPROP_COLOR,Magenta);
              ObjectSet("Trade "+cnt+S2[type]+" ",OBJPROP_COLOR,Magenta); break;
     case 5:  ObjectSet("Trade "+cnt+S2[type],OBJPROP_COLOR,Aqua);
              ObjectSet("Trade "+cnt+S2[type]+" ",OBJPROP_COLOR,Aqua); break;
     default: Alert("error: make_arrow() Unknown Type");
    }
   return;
  }

also add this function

double avbars()
  {double sum=0;
   for(int i=0; i<9; i++)
     sum+=(High[i]-Low[i])/10;
   return(sum);
  }
the make_arrow function uses this to calculate where to put the arrow so it is not mixed in with the price bars, so making it easier to see.
 
SDC:

you can use/modify mine

each arrow needs to have an exculsive number so make a static int counter and at each signal do cnt++

then use that as the first parameter, dir parameter is the arrow direction, type parameter is just to make a different color arrow for different types of signal, price is obviously just the bid or the ask or your MA value to position the star on the chart at the right place.

so if you have a buy signal, you call it like this make_arrow(cnt,0,0,ask);

That should make an upwards pointing arrow below the price bars and a star at the ask price, both the same color.

also add this function

the make_arrow function uses this to calculate where to put the arrow so it is not mixed in with the price bars, so making it easier to see.


Thank you so much. I am still playing with it. Can you send me a simple EA using this? It doesn't even have to be profitable, just want to see it in action.... I'm still getting compiler errors that I am working through.... thanks again.
 

you could run it as a script like this

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----function call parameters:
//----integer id, use counter for unique id.
//----integer dir, the direction for the arrow to Point
//----integer type, 0=buy 1=sell 2=buyclose 3=sellclose 4=custom 5=custom. (modify S2 for custom)
//----double price, price used for the star position co-ordinate.   
   make_arrow(1,1,1,Ask);
//----
   return(0);
  }
//+------------------------------------------------------------------+
void make_arrow(int id, int dir, int type, double price)
  {
//---- dirs: 0=up 1=down 2=sideways
   string S2[6]={" buy"," sell"," buyclose"," sellclose"," custom1"," custom2"};

   ObjectCreate("Trade "+id+S2[type],OBJ_ARROW,0,Time[0],0); 
   ObjectCreate("Trade "+id+S2[type]+" ",OBJ_ARROW,0,Time[0],price);
   switch(dir)
    {
     case 0:  ObjectSet("Trade "+id+S2[type],OBJPROP_ARROWCODE,241);
              ObjectSet("Trade "+id+S2[type],OBJPROP_PRICE1,price-avbars()-(type*Point));
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_ARROWCODE,172); break;
     case 1:  ObjectSet("Trade "+id+S2[type],OBJPROP_ARROWCODE,242);
              ObjectSet("Trade "+id+S2[type],OBJPROP_PRICE1,price+avbars()+(type*Point));
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_ARROWCODE,172); break;
     case 2:  ObjectSet("Trade "+id+S2[type],OBJPROP_ARROWCODE,243);
              ObjectSet("Trade "+id+S2[type],OBJPROP_PRICE1,price-avbars()-(type*Point));
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_ARROWCODE,172); break;
     default: Alert("error: make_arrow() Unknown Direction");
    }
   switch(type)
    {
     case 0:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Lime);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Lime); break;
     case 1:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Red);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Red); break;
     case 2:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Yellow);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Yellow); break;
     case 3:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Orange);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Orange); break;
     case 4:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Magenta);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Magenta); break;
     case 5:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Aqua);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Aqua); break;
     default: Alert("error: make_arrow() Unknown Type");
    }
   return;
  }
//+------------------------------------------------------------------+
double avbars()
  {
   double sum=0;
   for(int i=0; i<9; i++)
     sum+=(High[i]-Low[i])/10;
   return(sum);
  }
//+------------------------------------------------------------------+
 
SDC:

you could run it as a script like this


This is PERFECT... except it only triggers once.

I set it to trigger at a certain price, and it did... but then it never did it again...

How do you get it to trigger over and over if certain conditions are met...?

I want to be able to test my code for indicators by telling it to print the arrow when an indicator triggers... and every time it triggers.

Thank you so much for this... I am playing with it...

 
mrchuckw:


This is PERFECT... except it only triggers once.

I set it to trigger at a certain price, and it did... but then it never did it again...

How do you get it to trigger over and over if certain conditions are met...?

I want to be able to test my code for indicators by telling it to print the arrow when an indicator triggers... and every time it triggers.

Thank you so much for this... I am playing with it...


if (Ask > 1.35120) make_arrow(1,1,1,Ask);

This should print the arrow every bar when ask is above 1.35120

but it only prints once.

 

it will only run once as a script. I only said do that because you said you wanted to see if it works.

If you want it to do that multiple times you have to use it in an EA or indicator

 
SDC:

it will only run once as a script. I only said do that because you said you wanted to see if it works.

If you want it to do that multiple times you have to use it in an EA or indicator


Its great. I made it an ea, not a script... I've been playing with it and have learned alot about arrows. I still can't get it to print more than one arrow, so when I do my back test, I look at each arrow and analyze what happened, then change the date and move on.

Thanks for your help.

 

oh i see thats because you didnt make a counter to increment the arrow id, you cant have more than one arrow with the same name.

static int cnt=1;

if( your code to test a condition )
{
make_arrow(cnt,1,1,Ask);
cnt++;
}

will make new arrows every time the condition is true

 
SDC:

oh i see thats because you didnt make a counter to increment the arrow id, you cant have more than one arrow with the same name.

static int cnt=1;

if( your code to test a condition )
{
make_arrow(cnt,1,1,Ask);
cnt++;
}

will make new arrows every time the condition is true


Got it.... now it puts an arrow every time I tell it.

Thanks for your help.

Reason: