Translating PlotShapes


#1

hi, I used the following code to translate PlotShapes. But apparently I am not doing it correctly. Can anyone point me to the correct way? Thanks

				arg6[0].type = VAR_ARRAY;	arg6[0].array = iif.array;
				arg6[1].type = VAR_FLOAT;	arg6[1].val = TTBuyArrowColor.val;
				arg6[2].type = VAR_FLOAT;	arg6[2].val = 0.0f;
				arg6[3].type = VAR_ARRAY;	arg6[3].array = Low;
				arg6[4].type = VAR_FLOAT;	arg6[4].val = -15.0f;
				arg6[5].type = VAR_FLOAT;	arg6[5].val = 0.0f;
				gSite.CallFunction("PlotShapes", 6, arg6);

for the parameters 0 and 3 I use arrays. I am not getting an error but not seeing the expected shape either. The Low array is defined as

float *Low = gSite.GetStockArray(2);

and the iif.array as

				arg3[3].type = VAR_ARRAY;	arg3[0].array = BuyArray.array;
				arg3[3].type = VAR_ARRAY;	arg3[1].array = truepart.array;
				arg3[3].type = VAR_ARRAY;	arg3[2].array = falsepart.array;
				AmiVar iif = gSite.CallFunction("IIf", 3, arg3);

#2

Ed,

....
.....

AmiVar arg6[ 6 ];
arg6[0].type = VAR_ARRAY;    arg6[0].array = iif.array;
arg6[1].type = VAR_ARRAY;    arg6[1] = gSite.AllocArrayResult();
arg6[2].type = VAR_ARRAY;    arg6[2] = gSite.AllocArrayResult();
arg6[3].type = VAR_ARRAY;    arg6[3].array = Low;
arg6[4].type = VAR_ARRAY;    arg6[4] = gSite.AllocArrayResult();
arg6[5].type = VAR_ARRAY;    arg6[5] = gSite.AllocArrayResult();
  
int i, Barcount;
Barcount = gSite.GetArraySize();  
for( i = 0; i < Barcount; i++ ) {
   arg6[ 1 ].array[ i ] = TTBuyArrowColor.val;
   arg6[ 2 ].array[ i ] = 0.0f;
   arg6[ 4 ].array[ i ] = -15.0f;
   arg6[ 5 ].array[ i ] = 0.0f;  
}

AmiVar result = gSite.CallFunction( "PlotShapes", 6, arg6 );


#3

wow, thanks fx, will check it out!


#4

hi fx,

is this code working for you, I mean did you test it?

Your code seems correct but, I did not get it to work sofar.

I tested it to plot the “shapeUpArrow” which has number 1. So in the truepart array I put the value 1 where I want to draw a “shapeUpArrow”

First I thought there might be a problem with my BuyArray and therefor in the code below I also added PlotTextSetFont (for testing purposes) and that works. So the truepart array is filled. For the rest it seems ok, but it does not show the “shapeUpArrow”. Do you see an error somewhere?

			if (TTshowSignals.val)
			{
				AmiVar truepart, falsepart;
				truepart = gSite.AllocArrayResult();
				falsepart = gSite.AllocArrayResult();

				for (i = 0; i < nSize; i++)
				{
					falsepart.array[i] = 0.0f;
					truepart.array[i] = 0.0f;

					if (BuyArray.array[i] == 1.0f)
					{
						truepart.array[i] = 1.0f;

						arg8[0].type = VAR_STRING;
						arg8[0].string = (char *)gSite.Alloc(100);
						strcpy_s(arg8[0].string, 100, "p");
						arg8[1].type = VAR_STRING;	
						arg8[1].string = (char *)gSite.Alloc(100);
						strcpy_s(arg8[1].string, 100, "Wingdings 3");
						arg8[2].type = VAR_FLOAT;	arg8[2].val = TTFontPointsize.val;
						arg8[3].type = VAR_FLOAT;	arg8[3].val = (float)i;
						arg8[4].type = VAR_FLOAT;	arg8[4].val = Low[i];
						arg8[5].type = VAR_FLOAT;	arg8[5].val = TTBuyArrowColor.val;
						arg8[6].type = VAR_FLOAT;	arg8[6].val = TTTitleBackgroundColor.val;
						arg8[7].type = VAR_FLOAT;	arg8[7].val = 0.0f;
						gSite.CallFunction("PlotTextSetFont", 8, arg8);

					}
				}

				arg3[3].type = VAR_ARRAY;	arg3[0].array = BuyArray.array;
				arg3[3].type = VAR_ARRAY;	arg3[1].array = truepart.array;
				arg3[3].type = VAR_ARRAY;	arg3[2].array = falsepart.array;
				AmiVar iif = gSite.CallFunction("IIf", 3, arg3);

				arg6[0].type = VAR_ARRAY;    arg6[0].array = iif.array;
				arg6[1].type = VAR_ARRAY;    arg6[1] = gSite.AllocArrayResult();
				arg6[2].type = VAR_ARRAY;    arg6[2] = gSite.AllocArrayResult();
				arg6[3].type = VAR_ARRAY;    arg6[3].array = Low;
				arg6[4].type = VAR_ARRAY;    arg6[4] = gSite.AllocArrayResult();
				arg6[5].type = VAR_ARRAY;    arg6[5] = gSite.AllocArrayResult();

				for (i = 0; i < nSize; i++) 
				{
					arg6[1].array[i] = TTBuyArrowColor.val;
					arg6[2].array[i] = 0.0f;
					arg6[4].array[i] = -15.0f;
					arg6[5].array[i] = 0.0f;
				}
				gSite.CallFunction("PlotShapes", 6, arg6);
			}

#5

Yes, I have tested it. If I post untested code parts then usually I add comment “untested”.

I have not looked for further bugs in your code…
BUT (one) potential reason yours is not working is that your indexing of your IIf function is wrong.

You have

arg3[3].type = VAR_ARRAY;	arg3[0].array = BuyArray.array;
arg3[3].type = VAR_ARRAY;	arg3[1].array = truepart.array;
arg3[3].type = VAR_ARRAY;	arg3[2].array = falsepart.array;
AmiVar iif = gSite.CallFunction("IIf", 3, arg3);

but actually it should be

arg3[0].type = VAR_ARRAY;	arg3[0].array = BuyArray.array;
arg3[1].type = VAR_ARRAY;	arg3[1].array = truepart.array;
arg3[2].type = VAR_ARRAY;	arg3[2].array = falsepart.array;
AmiVar iif = gSite.CallFunction("IIf", 3, arg3);

#6

arghhhh!! I checked couple of times and didn’t see it. I must be drinking too little beer. Will up the dose and see if the problem disappears.

thanks a lot, it is working now … :blush:


#7

Ed,

BTW, your PlotShapes snippet of post#1 would work too since PlotShapes accepts array/float argument types. So no loop required (but via array types and applying looping it works too).

Just do this to test it

AmiVar VPlotShapes( int NumArgs, AmiVar *ArgsTable )
{	
	AmiVar arg6[ 6 ];
	arg6[0].type = VAR_ARRAY;	arg6[0].array = ArgsTable[ 0 ].array;// shape
	arg6[1].type = VAR_FLOAT;	arg6[1].val = 32.0f;// colorRed
	arg6[2].type = VAR_FLOAT;	arg6[2].val = 0.0f; // layer
	arg6[3].type = VAR_ARRAY;	arg6[3].array = gSite.GetStockArray(2);// Low (y-position)
	arg6[4].type = VAR_FLOAT;	arg6[4].val = -15.0f;// offset
	arg6[5].type = VAR_FLOAT;	arg6[5].val = 0.0f;// x-shift
	AmiVar result = gSite.CallFunction("PlotShapes", 6, arg6);
	return result;
}

In Function table add this

"epPlotShapes_C( shape )",	{ VPlotShapes, 1, 0, 0, 0, NULL },	

Compile in VS and then via AFL editor apply this example to chart pane (preferably on intra-day data).

dn = DateNum();
newday = dn != Ref( dn, -1);

Plot( C, "Price", colorDefault, styleCandle );
    
epPlotShapes_C( newday*shapeuparrow );  
// PlotShapes( newday*shapeUpArrow, colorRed, 0, L, -15, 0 ); 

You will see shapes at each new day start in color red and offset -15. No error messages.

So the sole reason of it not working originally was your wrong indexing of IIf function argument types. It is already wrong in first post of this thread but I haven’t recognized it the first time. :slight_smile:


#8

damn, you are right! All these problems because of a typo. Then from your initial example I understood that all the arguments should be of the same type, which made sense. But now it turns out that this is not necessary :smiley:

I was initially just translating plotshapes I use in my AFL but now I just removed the iif all together and use code below. But indeed it becomes time that I streamline this translating stuff a little so that I do not run in these typo problems. There are pieces of code I use over and over again, doing a lot of copying and pasting and sometimes I then make an error changing indexes etc.

i now use this

			if (TTshowSignals.val)
			{
				AmiVar ShapeUpArrow, ShapeDnArrow, BuyPriceIndicator, SellPriceIndicator;
				ShapeUpArrow = gSite.AllocArrayResult();
				ShapeDnArrow = gSite.AllocArrayResult();
				BuyPriceIndicator = gSite.AllocArrayResult();
				SellPriceIndicator = gSite.AllocArrayResult();

				for (i = 0; i < nSize; i++)
				{
					ShapeUpArrow.array[i] = 0.0f;
					ShapeDnArrow.array[i] = 0.0f;
					BuyPriceIndicator.array[i] = 0.0f;
					SellPriceIndicator.array[i] = 0.0f;

					if (BuyArray.array[i] == 1.0f)
					{
						ShapeUpArrow.array[i] = 1;
						BuyPriceIndicator.array[i] = 21;
					}
					if (SellArray.array[i] == 1.0f)
					{
						ShapeDnArrow.array[i] = 2;
						SellPriceIndicator.array[i] = 21;
					}

				}

				arg6[0].type = VAR_ARRAY;	arg6[0].array = ShapeUpArrow.array;
				arg6[1].type = VAR_FLOAT;	arg6[1].val = TTBuyArrowColor.val;
				arg6[2].type = VAR_FLOAT;	arg6[2].val = 0.0f;
				arg6[3].type = VAR_ARRAY;	arg6[3].array = Low;
				arg6[4].type = VAR_FLOAT;	arg6[4].val = -15.0f;
				arg6[5].type = VAR_FLOAT;	arg6[5].val = 0.0f;
				gSite.CallFunction("PlotShapes", 6, arg6);

				arg6[0].type = VAR_ARRAY;	arg6[0].array = BuyPriceIndicator.array;
				arg6[1].type = VAR_FLOAT;	arg6[1].val = TTBuypriceIndicationColor.val;
				arg6[2].type = VAR_FLOAT;	arg6[2].val = 0.0f;
				arg6[3].type = VAR_ARRAY;   arg6[3].array = BuyPriceArray.array;
				arg6[4].type = VAR_FLOAT;   arg6[4].val = 0.0f;
				arg6[5].type = VAR_FLOAT;	arg6[5].val = 0.0f;
				gSite.CallFunction("PlotShapes", 6, arg6);

				arg6[0].type = VAR_ARRAY;	arg6[0].array = ShapeDnArrow.array;
				arg6[1].type = VAR_FLOAT;	arg6[1].val = TTSellArrowColor.val;
				arg6[2].type = VAR_FLOAT;	arg6[2].val = 0.0f;
				arg6[3].type = VAR_ARRAY;	arg6[3].array = High;
				arg6[4].type = VAR_FLOAT;	arg6[4].val = -15.0f;
				arg6[5].type = VAR_FLOAT;	arg6[5].val = 0.0f;
				gSite.CallFunction("PlotShapes", 6, arg6);

				arg6[0].type = VAR_ARRAY;	arg6[0].array = SellPriceIndicator.array;
				arg6[1].type = VAR_FLOAT;	arg6[1].val = TTSellpriceIndicationColor.val;
				arg6[2].type = VAR_FLOAT;	arg6[2].val = 0.0f;
				arg6[3].type = VAR_ARRAY;   arg6[3].array = SellPriceArray.array;
				arg6[4].type = VAR_FLOAT;   arg6[4].val = 0.0f;
				arg6[5].type = VAR_FLOAT;	arg6[5].val = 0.0f;
				gSite.CallFunction("PlotShapes", 6, arg6);
			}