Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Alarm attached to horizontal line
 Post subject: Alarm attached to horizontal line Post rating: 0   New post Posted: Tue 11 Sep, 2012, 17:30 

User rating: 0
Joined: Thu 19 Jul, 2012, 09:21
Posts: 18
Location: Poland, Warsaw
Hello,

Is it possible to link horizontal line with sound alarm? Let's say I have got a couple horizontal lines on my chart and I want to set alarm on some of them in case a price will cross upward or downward. An alarm that bips not 4 times but as many times I want. I'd like to swap or change standard horizontal line file with my version with alarm (i'm affraid it's impossible but maybe exists some method to do with it). It would be excilent to add a visible level alarm not only some number level sort. I have to see that level because some people (including me) forget that things.
What do you think about that? ;)


 
The Best Answer  Post subject: Re: Alarm attached to horizontal line Post rating: 0   New post Posted: Wed 12 Sep, 2012, 07:31 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/#Strategy_interacting_with_a_chart_object
https://www.dukascopy.com/wiki/#Handle_chart_object_events
https://www.dukascopy.com/wiki/#Create_Alert


 
 Post subject: Re: Alarm attached to horizontal line Post rating: 0   New post Posted: Mon 15 Oct, 2012, 23:37 

User rating: 0
Joined: Thu 19 Jul, 2012, 09:21
Posts: 18
Location: Poland, Warsaw
I have learned java from two month but it's hard.
I'm trying to figure out how to code collecting of all objects in one list and then filling specific objects in another list. I have to ask you for help.
I wrote something like this:
public class Alarm implements IStrategy {
   //containers
   private List<AlarmLine> lineList;
   private List<IChartObject> chartObjectList;
   private Iterator<IChartObject> chartObjectIterator;
   private Iterator<AlarmLine> alarmLineIterator;
   
        //Other data
   ....   
   }



AlarmLine is my extended interface like this:
public interface AlarmLine extends IHorizontalLineChartObject{
   public enum AlarmDirection {
      UP,
      DOWN,
      DISABLED
   };   



Then in onStart I'm filling list in line 20:
@Override
   public void onStart(IContext context) throws JFException {
      // TODO Auto-generated method stub
      this.context = context;
      this.chart = context.getChart(this.instrument);
      this.console = context.getConsole();
      this.history = context.getHistory();
      this.formerTick = history.getLastTick(this.instrument);
      
      if(this.chart == null) {
         console.getErr().println("No chart opened for " + this.instrument);
         context.stop(); //stop the strategy
      }
      
      if(this.chart.getAll().size()>0) {
         this.startObjectCount = chart.getAll().size();
         this.objectCount = this.startObjectCount;
         
         //fill the list
         this.chartObjectList.addAll(chart.getAll());
         
      }
      
      //ITick tick = history.getLastTick(this.instrument);
      
      if(this.chartObjectList.isEmpty()) {
         console.getWarn().println("Add objects on chart!");
      }
      
      
   }


And then onTick but I don't know how to search all objects IChartObject in chartObjectList and copy AlarmLine objects to lineList. I wrote something like this in the line 20 below but it doesn't work and it's stupid but I have no idea
@Override
   public void onTick(Instrument instrument, ITick tick) throws JFException {
      // get number of objects and if it's changed clear both lists
      objectCount = chart.getAll().size();
      
      if(objectCount != startObjectCount) {
         if(lineList.size() != 0 && chartObjectList.size() != 0) {
            lineList.clear();
            chartObjectList.clear();
         }
         
         if(chart.getAll().size()>0) {
            startObjectCount = chart.getAll().size();
            objectCount = startObjectCount;
            
            //fill the list again
            chartObjectList.addAll(chart.getAll());
            
         }
         for(chartObjectIterator = chartObjectList.iterator(); chartObjectIterator.hasNext();) {
            //comparing all objects
            if(chartObjectList.iterator() == IHorizontalLine) {
               lineList.add(chartObjectList.iterator());
            }
         }
         
         startObjectCount = objectCount;
      }
   }

Anyway I want to select from chartObjectList objects of IHorizontalLine type. Do you have any suggestions?


 
 Post subject: Re: Alarm attached to horizontal line Post rating: 0   New post Posted: Tue 16 Oct, 2012, 07:34 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please describe more in detail what are you trying to do. Also when you post the example strategy then please post a full version such that we can adjust it and add some comments.


 
 Post subject: Re: Alarm attached to horizontal line Post rating: 0   New post Posted: Thu 18 Oct, 2012, 12:55 

User rating: 0
Joined: Thu 19 Jul, 2012, 09:21
Posts: 18
Location: Poland, Warsaw
As I said in my first post I'm trying to write a strategy to manage my alerts.
My system is based on some price levels. Those levels are drawn manually on chart by myself. I attached file with those levels.
I draw green and red lines and rectangles on chart. Red lines and rectangles trigger shorts, greens do opposite - longs. I still want to open my positions manually. A strategy has to only beep on this levels (and optionally send me mail ;) ).
I figured out that strategy has to collect all chart objects in some container then check if specific object is IHorizontalLine or IRectangle type. Then collect all IHorizontalLine objects in one container and IRectangle in other. If width of line or rectangle is bigger than normal (I set this on chart manually) then strategy determines its colour. When it's green then alarm enum is set on UP, when it's red it's set on DOWN. When width of object is normal then enum is set on DISABLED.
After starting strategy when price crosses green line or rectangle upwards or red ones downwards strategy has to play file choosen by user.
The user could also set a number of loops and when alarm beeps (after crossing level or closing bar).
I attached two files with source code. (By the way I suppose all code has to be in one file but I created it in Eclipse IDE). I have just started to write this code so there are errors. I will fix them but I stuck with checking obejcts in lists.
Thank you in advance ;)


Attachments:
eursudH4.png [18.37 KiB]
Downloaded 394 times
Alarm.java [4.18 KiB]
Downloaded 310 times
AlarmLine.java [201 Bytes]
Downloaded 302 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Alarm attached to horizontal line Post rating: 0   New post Posted: Mon 22 Oct, 2012, 07:43 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The problem with your described algorithm is that currently the strategy can only access its own-drawn objects. Thus it can't collect the object if it has been drawn manually, however, the strategy can plot the object and then you can modify it manually.


 
 Post subject: Re: Alarm attached to horizontal line Post rating: 0   New post Posted: Mon 22 Oct, 2012, 10:29 

User rating: 0
Joined: Thu 19 Jul, 2012, 09:21
Posts: 18
Location: Poland, Warsaw
Is this any chance to change standard objects? I would like to create my own line or rectangle with an alarm option or to change the standard alarm with a possibility to choose my own wav file, numer of loops and plotting visualy on a chart as a special line or something. The standard alarm is a joke :lol: Only a few beeps and no line.
If this modification is immposible please move my post to platform suggestion thread. I can't imagine how anyone could barely use something so proud called "ALARM" on this platform.


 
 Post subject: Re: Alarm attached to horizontal line Post rating: 0   New post Posted: Wed 07 Nov, 2012, 23:49 

User rating: 0
Joined: Thu 19 Jul, 2012, 09:21
Posts: 18
Location: Poland, Warsaw
I'm finishing my version of alarm with wav files but I want to play mp3 files on my alarm. I've searched this topic but I found it very hard. Can you help me with that? Is it possible to write a code to play mp3 files?

And one more question:
There are 2 options in my alarm:

- alarm on crossing downward/upward price.
This task performs onTick function but it plays erratic wave file (it's the matter of ticks that are very irregular). I would like playing wav file in smooth and regular manner

- alarm on closing bar/candle.
This task performs onBar function but it is called only one time on close and nothing more. Alarm plays 1 sec and no longer.

Maybe solution of my problems is event handler but I don't know how code it.
Any help?

P.S:
I've written an option of changing the alarm level by moving a line and solved temporary problem of situation when price crossed the line and then came back causing the alarm deactivation. Problem of closing bar is solved also but maybe exists better way than mine.


Attachments:
PriceBreakAlert.java [6.89 KiB]
Downloaded 290 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Alarm attached to horizontal line Post rating: 0   New post Posted: Fri 09 Nov, 2012, 11:18 

User rating: 0
Joined: Thu 19 Jul, 2012, 09:21
Posts: 18
Location: Poland, Warsaw
Here I've added option to choose alarm with only one line. Upper and lower respectively.
It would be nice to add a color chooser to definition parameters window but I haven't found any information about that.

Some sort of:
@Configurable("Color of lower line ") public Color colorLowerLine = Color.magenta;

only with possibility of call color panel or something ;)

This line sets a line color permanently with no option of change by the user...


Attachments:
PriceBreakAlert.java [7.13 KiB]
Downloaded 323 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com