Simple Coding Help - No Promise.

raj_singh

Well-Known Member
I am facing same issue with timeleft afl since i changed ami intraday settings to align minutes to regular market hours.Hourly candle starts at 9:15 and completes at 10:15 but afl keeps counting with normal hours that 9:00 to 10:00.
exactly what i want to say..

actually our exchange start at 00:15 (09:15) and this afl count time from 00:00 so on higher time frame we didn't get exact counting..



now what changes to made on afl so it think that candle start time is 00:15??
 
Last edited:
exactly what i want to say..

actually our exchange start at 00:15 (09:15) and this afl count time from 00:00 so on higher time frame we didn't get exact counting..


now what changes to made on afl so it think that candle start time is 00:15??
just add 900 seconds to SecsToGo

Code:
SecsToGo = TimeFrame - SecsLeft + 900;
I guess the above will work with 1 H and 30 minutes, but screw up below 15 minutes

try this not tested

Code:
 SecsToGo = IIf(TimeFrame==60*60 OR TimeFrame==60*30, TimeFrame - SecsLeft + Adjust,TimeFrame - SecsLeft);
 

raj_singh

Well-Known Member
just add 900 seconds to SecsToGo

Code:
SecsToGo = TimeFrame - SecsLeft + 900;
I guess the above will work with 1 H and 30 minutes, but screw up below 15 minutes

try this not tested

Code:
 SecsToGo = IIf(TimeFrame==60*60 OR TimeFrame==60*30, TimeFrame - SecsLeft + Adjust,TimeFrame - SecsLeft);
Code:
SecsToGo = TimeFrame - SecsLeft + 900;
yes it is working on 30 minute and 1 hour chart..:thumb:

Code:
 SecsToGo = IIf(TimeFrame==60*60 OR TimeFrame==60*30, TimeFrame - SecsLeft + Adjust,TimeFrame - SecsLeft);
[/QUOTE]

getting some error on this code :confused:
 
yes it is working on 30 minute and 1 hour chart..:thumb:

Code:
SecsToGo = IIf(TimeFrame==60*60 OR TimeFrame==60*30, TimeFrame - SecsLeft + Adjust,TimeFrame - SecsLeft);
getting some error on this code :confused:
yes the variable Adjust needs to be initialized . . .

Code:
Adjust = 900;
SecsToGo = IIf(TimeFrame==60*60 OR TimeFrame==60*30, TimeFrame - SecsLeft + Adjust,TimeFrame - SecsLeft);
Try it on different time frames and see if it is working as needed

Happy :)
 

KelvinHand

Well-Known Member
Code:
Hello,

  [SIZE="2"][I]Based on your current condition, you no need to stubbornly on using M1, M2  to assign the variables.
since,you know i is use to reference to 1min, 2min;[/I][/SIZE]


Yes,  but i was trying to do assign variable to each with M1 , m2  such way .
[B]Is it not possible without varget?
[/B]

I was trying to do in such way:
[IMG]http://i.imgur.com/34eJdzv.png[/IMG]
Should we use    [B]VarGet( "M" + 3<i<=5 ) ;[/B]
or if(i>3 AND i<=5) Writeif(up)  ... plottext..?


[COLOR="Black"][SIZE="3"]Since i don't know, How to do it without varset/varget 
[B]it's try with varset/varget[/B][/SIZE][/COLOR]

[CODE]
 SetBarsRequired( -2, -2 );   
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

dist = 0.1*ATR(1); 
for( i = 1; i < 5; i++ ) 
{ 

    TimeframeSet( i*in1Minute ); 
    up = C > O;      
    TimeframeRestore(); 
     
   VarSet( "M"+ i, TimeFrameExpand( up, i*in1Minute , expandPoint ) ); 
    
} 

for( i = 1; i < 5; i++ ) 
{ 
   m = VarGet( "M" + i ); 

   if (i==2 )
   if (i==3 )
   if (i==4 )
   if (i==5 )
    
   { 
      for( b = 0; b < BarCount; b++ ) {
     
         VarGet( "M" + i ) ;  
        
[COLOR="Red"][SIZE="4"]  if(i>3 AND i<=5  )    PlotText( "_m" , b, L[ b ]-1-dist[1], colorRed ); //Should we do something like this ? [/SIZE][/COLOR]
         

  
}}}
Since you asking to use without VarSet/VarGet,
and you want to capture M3 and M4 and M5 that Bull Candle at the same time
it is advisable to create all the needed before hand, easy for you

PHP:
SetBarsRequired( -2, -2 );
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

function tf_bull(n)
{
  tf = n * in1Minute;
  TimeframeSet(tf);
    up = C > O;
    TimeframeRestore();
    return TimeFrameExpand(up,tf,expandPoint);
    
}

m3  = tf_bull(3);
m4  = tf_bull(4);
m5  = tf_bull(5);
    
    for( b = 0; b < BarCount; b++ )
        if (M3[b] AND M4[b] AND M5[b]) 
           PlotText("3~5_M" , b, L[ b ], colorRed, colorDefault, -12 );

The other way you will facing problem, need counter, at your level, will be difficult.

If you keep flicking between these methods, that will cause problem to yourself. Therefore advise is Forget about VarGet/VarSet at this moment, wait till you really understand and practice how to do it.

I think enough of your problem, case close for me.
 
Last edited:
Since you asking to use without VarSet/VarGet,
and you want to capture M3 and M4 and M5 that Bull Candle at the same time
it is advisable to create all the needed before hand, easy for you

PHP:
SetBarsRequired( -2, -2 );
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

function tf_bull(n)
{
  tf = n * in1Minute;
  TimeframeSet(tf);
    up = C > O;
    TimeframeRestore();
    return TimeFrameExpand(up,tf,expandPoint);
    
}

m3  = tf_bull(3);
m4  = tf_bull(4);
m5  = tf_bull(5);
    
    for( b = 0; b < BarCount; b++ )
        if (M3[b] AND M4[b] AND M5[b]) 
           PlotText("3~5_M" , b, L[ b ], colorRed, colorDefault, -12 );
Hello,
thx
this example purpose to know exactly, how to use loops to get variable strings m1 to m5 ..
If i'm doing same stuff in seconds database
1min. = 60 seconds 5 min . = 300 seconds

I've to write such stuff for 300 times
m1,m2 ...to m300

If variable string m1 m2 m3 m4 m5 ...only solved by varset/varget
then I've no other way .


I tried with varset/varget

if(i>3 AND i<=5 ) PlotText( "_m" , b, L[ b ]-1-dist[1], colorRed );


when i try to do like this




It is not working with loops

m3 to m5 between ..
same if it's done with seconds
i.e. For just 1 minute

1 seconds to 60 seconds
each second increment represent as m1 m2 m3 m4 to m60


if there is something between m15 to m30
we need that in variable, that can be used ..

//if (m15 <i <m30) or if (i<15 and i<30)
If there is any value between this .. take that value in variable .

So that variable can be used .

I keep on searching it,if there is any way to do in amibroker,i guess there should be
 
Last edited:

LOVEENAJYOTHI

Well-Known Member
OK. Will look at it, but no promise.
Week day very busy. only weekend might got some time.

Let see whether any code expert will do it before me.
God bless you.
Desperately waiting for Weekend, fortunately we have an extended weekend this week thanks to Bakrid.

Thank u sooooooo much for your kindness.
May God Almighty shower his choicest blessings on you.

Regards
 

KelvinHand

Well-Known Member
Hello,
thx
this example purpose to know exactly, how to use loops to get variable strings m1 to m5 ..
If i'm doing same stuff in seconds database
1min. = 60 seconds 5 min . = 300 seconds

I've to write such stuff for 300 times
m1,m2 ...to m300

If variable string m1 m2 m3 m4 m5 ...only solved by varset/varget
then I've no other way .


I tried with varset/varget

if(i>3 AND i<=5 ) PlotText( "_m" , b, L[ b ]-1-dist[1], colorRed );


when i try to do like this




It is not working with loops

m3 to m5 between ..
same if it's done with seconds
i.e. For just 1 minute

1 seconds to 60 seconds
each second increment represent as m1 m2 m3 m4 to m60


if there is something between m15 to m30
we need that in variable, that can be used ..

//if (m15 <i <m30) or if (i<15 and i<30)
If there is any value between this .. take that value in variable .

So that variable can be used .

I keep on searching it,if there is any way to do in amibroker,i guess there should be
What so difficult ?
PHP:
SetBarsRequired( -2, -2 );
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

procedure Trash_Ridiculous_Set(bb,ee)
{
for (i=bb; i<=ee; i++)
{
  tf = i * in1Minute;
  TimeframeSet(tf);
    SAD = C<O;
    TimeframeRestore();
    VarSet("Trash"+i, TimeFrameExpand(SAD,tf,expandPoint));
}


}

function Trash_Ridiculous_Get(n)
{
    return VarGet("Trash"+n);
}

procedure HappyGoLucky_Set(bb,ee)
{
for (i=bb; i<=ee; i++)
{
  tf = i * in1Minute;
  TimeframeSet(tf);
    Happy = C> ref(C, -1);
    TimeframeRestore();
    VarSet("Trash"+i, TimeFrameExpand(Happy,tf,expandPoint));
}


}

function HappyGoLucky_Get(n)
{
    return VarGet("Happy"+n);
}


procedure tf_bull_set(bb,ee)
{
for (i=bb; i<=ee; i++)
{
  tf = i * in1Minute;
  TimeframeSet(tf);
    up = C > O;
    TimeframeRestore();
    VarSet("M"+i, TimeFrameExpand(up,tf,expandPoint));
}
    
}

function tf_bull_get(n)
{
    return VarGet("M"+n);
}

tf_bull_set(3,5);

m3  = tf_bull_get(3);
m4  = tf_bull_get(4);
m5  = tf_bull_get(5);
    
    for(b=0; b<BarCount; b++)
        if (M3[b] AND M4[b] AND M5[b]) 
           PlotText("3~5_M" , b, L[ b ], colorRed, colorDefault, -12 );  

Trash_Ridiculous_Set(15, 30);
TR15=Trash_Ridiculous_Get(15);

HappyGoLucky_Set(60,240);
HGL240=HappyGoLucky_Get(240);
For the benefit of your confuse mind.
 
Last edited:

KelvinHand

Well-Known Member
Didn't get who u r referring to ,
Pasting below 3 AFLs where Buttons are created on chart.
My Request is not for any full AFL, rather i need ur expert advise/ Guidance.

My Requirement;
Buy1=BuyCondition;
Buy2= PressBuyButton;
Buy=Buy1 OR Buy2;

Need coding guidance to PressBuyButton which if pressed, should trigger a Buy signal on Chart/Scan/Explore as a Valid Buy condition and the Signal should Remain permanently or atleast till the close of Amibroker.

Thanx n Rgrds
See How confuse your condition setup given:
Buy1=BuyCondition;
Buy2= PressBuyButton;
Buy=Buy1 Or Buy2;


And See what your need:
Need coding guidance to PressBuyButton which if pressed, should trigger a Buy signal on Chart/Scan/Explore as a Valid Buy condition and the Signal should Remain permanently or atleast till the close of Amibroker.


Break down below:

Buy1= Buy condition. eg MACD cross signal
Buy1_ButtonPressed =
if Buy1_Button not pressed then turn on Buy1 condition.
if Buy1_Button was pressed then turn off Buy1 condition.

For Chart/Scan/Explore。


I don't want to entertain you - because it not become simple coding help.

What you can do now is to study 1 simple AFL, as simple as posible.
eg.
PHP:
Title = "";
formulaName = "Control Panel";
GfxSetBkMode(1);
GfxSelectFont("Verdana", 18, 700, italic=False);
GfxSetTextColor(colorBrightGreen);
GfxTextOut(FormulaName, 20, 10);

_SECTION_BEGIN("Control Panel");
// Base point - Left Up Corner
X0 = Param ("X - Left Up Corner",   20,   4,  200, 10);
Y0 = Param ("Y - Right Up Corner",   120,  40, 200, 10);

// --- Button pressed
LBClick = GetCursorMouseButtons() == 9;	// Click
MouseX  = Nz(GetCursorXPosition(1));		// 
MouseY  = Nz(GetCursorYPosition(1));		// 

// --- Button Draw
procedure DrawBut (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
	GfxSetOverlayMode(0);
	GfxSelectFont("Verdana", 9, 700);
	GfxSetBkMode(1);
	GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
	GfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16);
}
GfxSetTextColor(colorWhite);

// Button Begin
DrawBut ("Begin", X0, Y0, X0+170, Y0+30, colorGrey40, colorGrey40);
CursorInResetBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0 AND MouseY <= Y0+30;
ResetPressed = CursorInResetBut AND LBClick;
if (ResetPressed) 
{ 
StaticVarSet ("RS", 1);      
StaticVarSet ("AutoOn",  0); 
StaticVarSet ("AutoOff", 1); 
StaticVarSet ("SMKT",    0); 
StaticVarSet ("BMKT",    0);
StaticVarSet ("CLPOS",   0);
StaticVarSet ("CANC",    0);
StaticVarSet ("ExpOn",   0); 
StaticVarSet ("ExpOff",  1);
}

// Button Auto on
DrawBut ("Auto on", X0, Y0+40, X0+170, Y0+70, colorDarkGreen, colorDarkGreen);
CursorInAutoOnBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+40 AND MouseY <= Y0+70;
AutoOnPressed = CursorInAutoOnBut AND LBClick;
if (AutoOnPressed) 
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("AutoOn",  1);
StaticVarSet ("AutoOff", 0);
StaticVarSet ("SMKT",    0); 
StaticVarSet ("BMKT",    0);
StaticVarSet ("CLPOS",   0);
StaticVarSet ("CANC",    0);
}

// Button Auto off
DrawBut ("Auto off", X0, Y0+80, X0+170, Y0+110, colorDarkRed, colorDarkRed);
CursorInAutoOffBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+80 AND MouseY <= Y0+110;
AutoOffPressed = CursorInAutoOffBut AND LBClick;
if (AutoOffPressed) 
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("AutoOn",  0); 
StaticVarSet ("AutoOff", 1);
StaticVarSet ("SMKT",    0); 
StaticVarSet ("BMKT",    0);
StaticVarSet ("CLPOS",   0);
StaticVarSet ("CANC",    0);
}

// Button Sell Market
DrawBut ("Sell Market", X0, Y0+130, X0+170, Y0+180, colorRed, colorRed);
CursorInSMKTBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+130 AND MouseY <= Y0+180;
SMKTPressed = CursorInSMKTBut AND LBClick;
if ( SMKTPressed AND StaticVarGet ("AutoOff")==1  AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  1);
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  0);
}

// Button Buy Market
DrawBut ("Buy Market", X0, Y0+190, X0+170, Y0+240, colorLime, colorLime);
CursorInBMKTBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+190 AND MouseY <= Y0+240;
BMKTPressed = CursorInBMKTBut AND LBClick;
if ( BMKTPressed AND StaticVarGet ("AutoOff")==1  AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  1);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  0);
}

// Button Close Position
DrawBut ("Close Position", X0, Y0+250, X0+170, Y0+300, colorGrey40, colorGrey40);
CursorInCloseBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+250 AND MouseY <= Y0+300;
ClosePressed = CursorInCloseBut AND LBClick;
if ( ClosePressed AND StaticVarGet ("AutoOff")==1  AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 1);
StaticVarSet ("CANC",  0);
}

// Button Cancel All Orders
DrawBut ("Cancel All Orders", X0, Y0+310, X0+170, Y0+360, colorGrey40, colorGrey40);
CursorInCancelBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+310 AND MouseY <= Y0+360;
CancelPressed = CursorInCancelBut AND LBClick;
if ( CancelPressed AND StaticVarGet ("AutoOff")==1 AND StaticVarGet ("ExpOn")==1 )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  1);
}

// Button Export On
DrawBut ("Export On", X0, Y0+380, X0+170, Y0+410, colorDarkGreen, colorDarkGreen);
CursorInExpOnBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+380 AND MouseY <= Y0+410;
ExpOnPressed = CursorInExpOnBut AND LBClick;
if ( ExpOnPressed )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("ExpOn",  1);
StaticVarSet ("ExpOff", 0); 
}

// Button Export Off
DrawBut("Export Off", X0, Y0+420, X0+170, Y0+450, colorDarkRed, colorDarkRed);
CursorInExpOffBut = MouseX >= X0 AND MouseX <= X0+170 AND MouseY >= Y0+420 AND MouseY <= Y0+450;
ExpOffPressed = CursorInExpOffBut AND LBClick;
if ( ExpOffPressed )
{ 
StaticVarSet ("RS", 0);
StaticVarSet ("ExpOn", 0); 
StaticVarSet ("ExpOff",1);
StaticVarSet ("SMKT",  0); 
StaticVarSet ("BMKT",  0);
StaticVarSet ("CLPOS", 0);
StaticVarSet ("CANC",  0);
}

if(StaticVarGet("RS")==1)			{DrawBut("", X0+180, Y0,     X0+210, Y0+30,  colorGrey40, colorGrey40);		}// RS=1			
if(StaticVarGet("AutoOn")==1)	{DrawBut("", X0+180, Y0+40,  X0+210, Y0+70,  colorDarkGreen, colorDarkGreen);}// AutoOn		
if(StaticVarGet("AutoOff")==1)	{DrawBut("", X0+180, Y0+80,  X0+210, Y0+110, colorDarkRed, colorDarkRed);	}// AutoOff	
if(StaticVarGet("SMKT")==1)		{DrawBut("", X0+180, Y0+130, X0+210, Y0+180, colorRed, colorRed);				}// SMKT			
if(StaticVarGet("BMKT")==1)		{DrawBut("", X0+180, Y0+190, X0+210, Y0+240, colorLime, colorLime);			}// BMKT			
if(StaticVarGet("CLPOS")==1)		{DrawBut("", X0+180, Y0+250, X0+210, Y0+300, colorGrey40, colorGrey40);		}// CLPOS		
if(StaticVarGet("CANC")==1)		{DrawBut("", X0+180, Y0+310, X0+210, Y0+360, colorGrey40, colorGrey40);		}// CANC			
if(StaticVarGet("ExpOn")==1)		{DrawBut("", X0+180, Y0+380, X0+210, Y0+410, colorDarkGreen, colorDarkGreen);}// ExpOn		
if(StaticVarGet("ExpOff")==1)	{DrawBut("", X0+180, Y0+420, X0+210, Y0+450, colorDarkRed, colorDarkRed);		}// ExpOff		

_SECTION_END();
look at where is the StaticVarGet() , eg
put in a procedure in it:

if(StaticVarGet("ExpOn")==1)
{
ProcessBuy1Condition(true);
DrawBut("", X0+180, Y0+380, X0+210, Y0+410, colorDarkGreen, colorDarkGreen);
}// ExpOn

if(StaticVarGet("ExpOff")==1)
{
ProcessBuy1Condition(false);
DrawBut("", X0+180, Y0+420, X0+210, Y0+450, colorDarkRed, colorDarkRed);
}// ExpOff

before that define your Buy1 Condition & ProcessBuy1Condition

Buy1 = Cross(macd(), signal());

procedure ProcessBuy1Condition(Trigger)
{

if (Trigger)
{
Buy = Buy1;
Plotshape Buy Arrow .....
}
else
Buy = false;

}

Some thing like that.

Then try to use the log window and _TRACE() setup debug point to check what went wrong.
The best is to upgrade to Version 6.10 and above, to use also with the DEBUGGER to set breakpoint and step through the program and
watch the variables ....etc.

To reduce errors, it always good to work in a separate standalone module level first for your buy condition, before assemble to the unit level.


End of advice/coding guidance
 
Last edited:
I have an idea for intraday trade .And I manuel checked its succesfull.

when no trend in market system more buy and more sell trade .And the trade usually lost.this time trades are same day usually.

*I think that when same day trade dont enter trade no buy and sell...only stoploss and wait.
*when same day trade stoploss and wait %1 it moves in the direction.

Example
This sample code

buy = C >WMA(C,50);
sell= C <WMA(C,50);


example trade

date 06.06.2016
stock=XYZ future market
stock price=10.000

My system buy enter 09:45 in time

And my system give sell signal same day 12:15 in time stock price is 10.000.For the same day dont enter and stoploss and wait.And if price down %1 (9.900) we enter sell..%1 delayed. Even if the same day(big trend possibility).

if trades not same day we dont follow this rule..

is it include this rule any system example this formula

mBull = C >WMA(C,50);
mBear= C <WMA(C,50);
 
Last edited:

Similar threads