"bi == start" as one variable and "bi == stop" as the second variable and subtract the two like this: diff = bi == stop - bi == start. Is this correct?On 3/6/2016 11:45 AM, fxshrat wrote:
That code has some flaws/overkills
overkill:
using SetBarsRequired( sbrall, sbrall ); just makes code slow because of using all bars
If you want to know overall bi in Information window then use status( "quickaflfirstdatabar" )
Like so,
qfdb = status( "quickaflfirstdatabar" );
printf( "startBi: %g\nendBi: %g", (qfdb + start), (qfdb + stop) );
Then you don't require SetBarsRequired(sbrall)
coding flaws:
using LastValue( SelectedValue( bi ) )
just use SelectedValue( bi )
since both LastValue and SelectedValue are used on arrays but not on scalars.
Using both together makes not sense.
some other note
IIf(bi==start,1,0) can be repalced by just using bi == start (same for stop)
StaticVarSet( "StartbarBi"+getchartid(), SelectedValue(BI)) is never called by any StatiVarGet.
So it is code cadaver, so to say. So it can be removed. It just confuses.
So modified code
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Price", IIf( C < O,colorGrey50, colorGrey50), styleCandle ) ;
///////////Find the Start and End barindex by pressed by CLR or Shift + Left mouse Click////////////
B = GetCursorMouseButtons();
Control_Pressed = GetAsyncKeyState( 17 ) < 0; // CONTROL key pressed,
Shift_Pressed = GetAsyncKeyState( 16 ) < 0; // Shift key pressed,
bi=BarIndex(); Lbi =LastValue(bi);
if( B & 1 AND CONTROL_Pressed )
{
StartBi = SelectedValue( BI );
StaticVarSet( "StartBi" + getchartid(), StartBi ) ;
}
if( B & 1 AND Shift_Pressed )
{
endBi = SelectedValue( BI );
StaticVarSet( "endBi" + getchartid(), endBi );
}
if ( B & 4) { StaticVarRemove("*Bi"+ getchartid()); }
//////////////////////////////////////////////////////////
start = StaticVarGet( "StartBi" + getchartid() );
stop = StaticVarGet( "endBi" + getchartid() );
qfdb = Status( "quickaflfirstdatabar" );
printf( "startBi: %g\nendBi: %g", (qfdb + start), (qfdb + stop) );
Plot( bi == start, "StartBI", colorgreen, styleHistogram | styleDashed | styleOwnScale | styleNoLabel ); // start bar styleHistogram
Plot( bi == stop, "stopBI", colorred, styleHistogram | styleDashed | styleNoLabel | styleOwnScale ); // End bar styleHistogram
Alan alan@thenorthams.us [amibroker] wrote:
Panos- Thanks for sharing the code. I saved it as a snippet for later use. Seems like this would be a good function for Tomasz to add to the AFL library. -Alan
On 3/5/2016 6:01 PM, Panos Boufardeas panosbouf@freemail.gr [amibroker] wrote:
Hello.. as for your first Question use the below code
>> I am trying to do the following:
>> 1- store multiple dates on a click of a mouse in daily or intraday.
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Price", IIf( C < O,colorGrey50, colorGrey50), styleCandle ) ;
SetBarsRequired ( sbrAll, sbrAll );
///////////Find the Start and End barindex by pressed by CLR or Shift + Left mouse Click////////////
B = GetCursorMouseButtons();
Control_Pressed = GetAsyncKeyState( 17 ) < 0; // CONTROL key pressed,
Shift_Pressed = GetAsyncKeyState( 16 ) < 0; // Shift key pressed,
bi=BarIndex(); Lbi =LastValue(bi);
if ( B & 1 AND CONTROL_Pressed )
{
StartBi= LastValue( SelectedValue(BI) );
StaticVarSet( "StartBi"+getchartid(), StartBi) ;
StaticVarSet( "StartbarBi"+getchartid(), SelectedValue(BI)) ;
}
if ( B & 1 AND Shift_Pressed )
{
endBi = LastValue( SelectedValue(BI) );
StaticVarSet( "endBi"+getchartid(), endBi);
}
if ( B & 4) { StaticVarRemove("*Bi"+ getchartid()); }
//////////////////////////////////////////////////////////
start=StaticVarGet( "StartBi"+getchartid()); "startBi " + WriteVal(start);
stop= StaticVarGet("endBi"+getchartid()); "stopBi " + WriteVal(stop);
Plot( IIf(bi==start,1,0), "StartBI", colorgreen, styleHistogram |styleDashed|styleOwnScale |styleNoLabel); // start bar styleHistogram
Plot( IIf(bi==stop,1,0), "stopBI", colorred, styleHistogram|styleDashed|styleNoLabel |styleOwnScale ); // End bar styleHistogram
Panos
On 05-03-16 3:55 PM, portfoliobuilder99@gmail.com [amibroker] wrote:For a couple of your questions these may help.
You want to draw an arc? See attached screen shot or maybe what you are looking for is here:ORhttp://www.amibroker.com/guide/afl/gfxarc.html
You want to count bars between conditions? perhaps these posts will help get you started
http://amibrokerforum.proboards.com/thread/101/bars-different-value-condition
http://amibrokerforum.proboards.com/thread/75/start-period-recognition
But I agree with Alan. Try finding a solution, post your code and then ask why it is not working. When asking questions on the forum be specific, give an example or a detailed explanation.
Try a "Search" on this forum as many topics have been discussed.
Try eMail AmiBroker technical support if there is no help on this forum.
There are many code writers for hire. Google search AmiBroker code writing and hire someone to help you.
Posted by: Alan <alan@thenorthams.us>
| Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (9) |
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
EmoticonEmoticon